Arpan Biswas
Arpan Biswas

Reputation: 185

Can we use 'where' in a lambda function in Haskell?

I was wondering if we can use where in an anonymous function or not. I tried to do it in this way:

\x -> k where k = x+1

But this gives a parse error on 'where'.

Upvotes: 0

Views: 1129

Answers (1)

dfeuer
dfeuer

Reputation: 48591

You can use where in certain expressions within a lambda expression, but not just inside.

f = \x ->
  case x of
    Nothing -> 12
    Just y -> z * 2
      where z = y + 7

Upvotes: 5

Related Questions