4 ms·
mySubroutine = do foo <- mkFoo bar <- mkbar foo mkBaz bar mySubroutineV2 = mkFoo >>= \foo -> mkBar foo >>= \bar ->
by solomonb 2y ago
mySubroutine = do
foo <- mkFoo
bar <- mkbar foo
mkBaz bar
mySubroutineV2 =
mkFoo >>= \foo ->
mkBar foo >>= \bar ->
mkBaz bar
- edflsafoiewq 2y agoNote that this is same desugaring for normal let let x = y in F <===> (\x.F)(y) just replacing function application with a different function (>>=).
- solomonb 2y agoYou can desugar let bindings that way but often times (as I believe is the case in GHC) you have a `Let` term in your AST.
- Athas 2y agoThis is not the case in Haskell, because let-bindings can be self-referential, while lambdas cannot (without using a fixed point combinator). Also, in most functional languages, a let-binding causes type generalisation, which is not the case for a lambda.
- chombier 2y agoNot exactly the same: `x` is given a polymorphic type (in F) in Haskell (restricted to values in ML) whereas the unannotated let-over-lambda will give `x`a monomorphic type.