Instantly share code, notes, and snippets.

Embed
What would you like to do?
-- Monad の (>>=) に相当
comb m n = let (a, log1) = m
(b, log2) = n a
in (b, log1 ++ log2)
-- Monad の (>>) に相当
comb_ m n = m `comb` \x -> n
-- Monad の return に相当
ret x = (x, "")
-- 出力のための関数
out x = ((), show x ++ ",")
outStr x = ((), x)
main = print $ outStr "begin: " `comb_`
ret (1 + 2) `comb` \a ->
out a `comb_`
ret (a * 3) `comb` \b ->
out b `comb_`
ret (b - 4) `comb` \c ->
out c `comb_`
outStr " :end" `comb_`
ret c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment