let-where difference
The program f = [ 1, 2, (a+b where a = 1 b = 2 ) ] is qualified by some compilers as a wrong syntax. And f = [ 1, 2, (let a = 1 b = 2 in a+b ) ] is accepted. What may be the reason for such difference, is this a `bug' in Haskell-98 ? (Usually `let' and `where' are moved out of such a list construct, but for a large list with non-trivial expressions for the members, it may be natural to remain them). Thank you in advance for the explanation. Copy, please, the answer to mechvel@botik.ru ----------------- Serge Mechveliani mechvel@botik.ru
Let is part of an expression, whereas where is part of a declaration. Your first program should be rejected, since lists can only be made up of expressions. That is, the 'where' in example 1 *must* come after the entire expression [ 1, 2, ... ] so that it can be part of the declaration of f. OTOH, the let/in in example 2 is fine in situ, because it is part of an epxression, which is allowed for let/in constructs. On Mon, 22 Dec 2003, Serge D. Mechveliani wrote:
The program f = [ 1, 2, (a+b where a = 1 b = 2 ) ] is qualified by some compilers as a wrong syntax. And f = [ 1, 2, (let a = 1 b = 2 in a+b ) ] is accepted. What may be the reason for such difference, is this a `bug' in Haskell-98 ?
(Usually `let' and `where' are moved out of such a list construct, but for a large list with non-trivial expressions for the members, it may be natural to remain them).
Thank you in advance for the explanation. Copy, please, the answer to mechvel@botik.ru
----------------- Serge Mechveliani mechvel@botik.ru
_______________________________________________ Haskell mailing list Haskell@haskell.org http://www.haskell.org/mailman/listinfo/haskell
-- Hal Daume III | hdaume@isi.edu "Arrest this man, he talks in maths." | www.isi.edu/~hdaume
On Mon, Dec 22, 2003 at 07:15:32AM -0800, Hal Daume III wrote:
Let is part of an expression, whereas where is part of a declaration. Your first program should be rejected, since lists can only be made up of expressions. That is, the 'where' in example 1 *must* come after the entire expression [ 1, 2, ... ] so that it can be part of the declaration of f. OTOH, the let/in in example 2 is fine in situ, because it is part of an epxression, which is allowed for let/in constructs.
You can introduce declaration context in expressions using 'let', for example: f = [ 1, 2, (let x = a+b where a = 1 b = 2 in x ) ] Of course it is quite pointless, because then you have both 'let' and 'where'. Best regards, Tom -- .signature: Too many levels of symbolic links
participants (3)
-
Hal Daume III -
Serge D. Mechveliani -
Tomasz Zielonka