3

I want to have access to a let-binding within a following where-clause.

Why does this Code fail? And even more important: How do I get it to work?

test bar = let baz = bar - 1 in
 foo where
  foo = baz`

it says: Not in scope: baz' Perhaps you meantbar'

1
  • 1
    Did you really mean to write baz' or was it baz that you wanted? Commented Dec 10, 2013 at 14:46

2 Answers 2

3

You can think of a where as another way to write a let around the right hand sides that belong to a single match.

In your case, it is quite easy, as there is only a single right hand side. Hence, you wrote:

test bar = let foo = baz in let baz = bar-1 in foo

This is not going to work. I recommend to stick with either where or let, most idiomatic would be:

test bar = foo
    where
       foo = baz
       baz = bar -1

Apart from that, when you only define baz then baz' will never be in scope.

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

Comments

0

where clauses can only access the parameters of the enclosing function and any higher-level bindings. You can pass baz as a parameter to foo:

test bar = let baz = bar - 1 in (foo baz)
  where foo x = x

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.