Syntactic constructs with WHERE in haskell. (Beginner)

In the book Learn You a Haskell for Great Good! it states the let is an expression and where is just a syntactical construct.

Is syntactical construct the same as syntactic sugar in this context. If not, what does it mean by the 2 words syntactical construct?

1 Like

It means that it has no deeper meaning, and is converted to let once the syntax part of the compilation process is over


I have a different spin from @Kleidukos: My interpretation is that let can be used anywhere an expression is used. So we can say blurt y = let x = 5 in frob (x + x + y) or blurt y = frob (let x = 5 in x + x + y) or even blurt y = frob ((let x = 5 in x) + (let x = 5 in x) + y). This is what "let is an expression" means: it’s part of the recursive structure of expressions. On the other hand, where is part of a few regimented bits of syntax (a.k.a. “syntactic constructs”), including function/variable equations (which have an = in them) and case alternatives. But you can’t put where anywhere else!

Maybe it’s also helpful to say that “syntactic construct” is a very general term just meaning “bit of syntax”, while “expression” is a specific term referring to the part of a Haskell program that happens, for example, after the = in blurt x =. So an expression is a syntactic construct, but not every syntactic construct is an expression. I don’t connect “syntactic construct” with “syntactic sugar”.

I hope this is helpful!


Thank you! I love this explanation.