1

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'
melpomene
  • 84,125
  • 8
  • 85
  • 148
CarryOn
  • 11
  • 1

1 Answers1

2

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.

chepner
  • 497,756
  • 71
  • 530
  • 681