do式はbindの糖衣構文
from do式
do式はbindの糖衣構文
https://www.nslabs.jp/haskell-do-notation.rhtml
https://qiita.com/Yametaro/items/d12ec13de82d221702de
elm,scalaのandThen
/mrsekut-book-lambda-5-2/012: 1.2 モナドとは「do式が使える構造」である
code:haskell
m >>= f >>= g
code:haskell
do x <- m -- アクションmの結果をxに束縛. アクションから値を取り出す
y <- f x -- xにアクションfを適用した結果をyに束縛
g y -- yにアクションgを適用
doブロックの各行はbindで結ばれている
code:hs
main = do
print "hello"
print "world"
main = -- 上と同じ
print "hello" >>= \_ ->
print "world"
https://qiita.com/tezca686/items/78d099987894ac7bec48#準備do構文
わかりやすいmrsekut.icon
code:doあり.hs
hoge x = do
foo <- m
bar <- mFunction x
m''
return $ foo + bar
code:doなし.hs
hoge x = (
m >>= (\foo ->
mFunction x >>= (\bar ->
m'' >>= (\_ ->
return $ foo + bar
))))