2

I'm just trying to see if WinGHCi works for Haskell programming, and I don't know the reason why this shows the error above.

I do not know if this is the right application to work on Haskell, if you know another one that can actually work, I would appreciate.

f (x:xs) = f ys ++ [x] ++ f zs
 where
 ys = [a | a ← xs, a ≤ x]
 zs = [b | b ← xs, b > x]
<interactive>:21:20: error:
    parse error on input ‘=’
    Perhaps you need a 'let' in a 'do' block?
    e.g. 'let x = 5' instead of 'x = 5'
8
  • 2
    That's declaration syntax, for files, not ghci. Commented Sep 5, 2019 at 16:09
  • 1
    You want to read the GHCi manual. Also possibly upgrade your Haskell installation if it's older than version 8. Commented Sep 5, 2019 at 16:40
  • @melpomene isn't this supported since GHC 8 or so? Commented Sep 5, 2019 at 16:40
  • @n.m. not multi-line. Also, related question: stackoverflow.com/questions/18162420/… Commented Sep 5, 2019 at 16:48
  • @AJFarmar :set +m perhaps? Note the question is from 2013. Commented Sep 5, 2019 at 16:56

1 Answer 1

3

There are two intertwined issues: whether you need let to introduce a definition, and whether you can write a multiline definition.

First, let. Prior to 8.0, GHCi required a definition be introduced with let:

let f (x:xs) = ...

Starting in 8.0, you can drop the let, and GHCi will figure out what you are trying to do.

As for the multiline statement, there are two ways you can do this. One is to explicitly delimit your block with :} and :{:

Prelude> :{
Prelude| f (x:xs) = f ys ++ [x] ++ f zs
Prelude|  where
Prelude|  ys = [a | a <- xs, a <= x]
Prelude|  zs = [b | b <- xs, b > x]
Prelude| :}

The other, enabling multiline mode with :set +m, appears to be picker about what it accepts.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.