Question about scope of 'let' and 'where'

Hal Daume III hdaume@ISI.EDU
Sun, 16 Mar 2003 22:00:56 -0800 (PST)


It is not.  Lets are expressions.  Wheres are part of declarations.  In a
grammar sense, you have something like:

funcdef ::= name = expr (where decls)?
expr    ::= let decls in expr

so the declarations inside a let are internal to the expression and can't
go outside into the where clause.

--
 Hal Daume III                                   | hdaume@isi.edu
 "Arrest this man, he talks in maths."           | www.isi.edu/~hdaume

On Sun, 16 Mar 2003, Graham Klyne wrote:

> In the function body (rhs):
> 
>      let
>          { a = (e1) }
>      in
>         (e2)
>         where
>              { b = f a }
> 
> Does the Haskell specification indicate that the definition of 'a' is 
> in-scope for the definition of 'b'?
> 
> Practical experience using HUGS suggests the answer is no, but my intuition 
> is that the answer should be yes.
> 
> I was unable to find anything in either the report or the "gentle 
> introduction" that made the correct answer clear to me (which is not to say 
> it's not there, just that I didn't find it).  I think the tutorial might 
> benefit from a discussion of what is in-scope for where clauses.
> 
> <comment>
> FWIW, my intuition was that
> 
>      e where defs
> 
> was a form of expression (like let ... in), in which some sub-expressions 
> were factored out as subsidiary definitions;  i.e. that I'd expect to be 
> able to replace each occurrence of a name defined by 'where' with the body 
> of the corresponding definition.  Hence I'd expect the let definitions to 
> be in-scope.
> 
> I now see that use of 'where' is restricted to specific contexts.  I wonder 
> if such restriction is needed?  The differences between let and where in 
> Haskell are something I find to be confusing.
> </comment>
> 
> #g
> 
> 
> -------------------
> Graham Klyne
> <GK@NineByNine.org>
> PGP: 0FAA 69FF C083 000B A2E9  A131 01B9 1C7A DBCA CB5E
> 
> _______________________________________________
> Haskell mailing list
> Haskell@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell
>