
On Tuesday 07 June 2011, 19:01:29, aditya siram wrote:
Also I don't really know how "let"s inside a do block desugars but I'm guessing it's simple substitution
Yes. do let a = b foo bar desugars to let a = b in do { foo; bar; } (and then further to let a = b in foo >> bar). A bit more interesting are things like do x <- foo let a = b bar which desugars to foo >>= \x -> let a = b in bar and then the compiler may lift the let-binding out of the (>>=) if a) that's possible because it doesn't use any values bound in the do-block before and b) it's deemed a beneficial transformation (which I think it is, so at least with optimisations, I'd expect such lets to be floated out).
so for example the "main" function below probably translates to: main3 = let suffix = "suffix" in getLine >>= \x -> return (map toUpper x ++ suffix)
-deech