haskellcompiler-errorsfunctional-programmingghc

Haskell parse error on input `<-'


Can't seem to line up (indent) this code correctly in Haskell. Getting error:

parse error on input `<-'

Can anyone spot where the error is at:

evalListSplitAt n stratPref stratSuff [] = return []
evalListSplitAt n stratPref stratSuff xs = do ys` <- stratPref ys
                                              zs` <- stratSuff zs
                                            return (ys` ++ zs`)
                                            where (ys,zs) = splitAt n xs

Cheers.


Solution

  • You need to indent every line in a do block equally. Also, make sure to use ' for variable names rather than `. (That is, use an apostrophe rather than a backtick. Backticks are used for making functions infix, so they cannot be used as part of a variable name. So you can name something "x prime" using an apostrophe: x'.) So your code should look something like this:

    evalListSplitAt n stratPref stratSuff [] = return []
    evalListSplitAt n stratPref stratSuff xs = do ys' <- stratPref ys
                                                  zs' <- stratSuff zs
                                                  return (ys' ++ zs')
                                            where (ys,zs) = splitAt n xs