It's well known that <-
in do
blocks are just syntactic sugar for >>=
, but is <-
defined anywhere in the Haskell source or is it just syntactic construction that is part of language grammar and thus the parser just replaces every <-
with appropriate form of >>=
?
Asked
Active
Viewed 212 times
1
1 Answers
5
The Do Expression is part of the Language.
From the Haskell Language Report 2010:
3.14 Do Expression
lexp → do { stmts } (do expression) stmts → stmt1 … stmtn exp [;] (n ≥ 0) stmt → exp ; | pat <- exp ; | let decls ; | ; (empty statement)
A do expression provides a more conventional syntax for monadic programming. It allows an expression such as
putStr "x: " >> getLine >>= \l -> return (words l)
to be written in a more traditional way as:
do putStr "x: " l <- getLine return (words l)
As indicated by the translation of do, variables bound by let have fully polymorphic types while those defined by <- are lambda bound and are thus monomorphic.
see Do Expression of the Haskell Language Report.

andih
- 5,570
- 3
- 26
- 36