haskell - Types and do notation -
this several questions rolled one:
in
do
notation, each line have return same type? example, can write 1 line in singledo
block returnsio
monad, , returns integer? (my understanding, based on how de-sugaring>>
,>>=
seems work, answer no.)if not, how compiler determine type lines must return? in examples i've seen, author takes foregone conclusion we're working
io
monads. how know, givendo
block, each line must return?again assuming answer #1 no: how use functions don't return right kind of monad inside
do
block? example, consider websockets code:application :: mvar serverstate -> ws.request -> ws.websockets ws.hybi00 () application state rq = ws.acceptrequest rq msg <- ws.receivedata :: ws.websockets ws.hybi00 text return ()
suppose want print value of
msg
. how go in way doesn't conflict type ofdo
block?
- in do-block, each line can return different types, must in same monad
- one line can return
io string
, 1 can returnio integer
both haveio
.
- one line can return
- the same rest of haskell. type inference. in rest of haskell doesn't work, , when doesn't must annotate well.
- there 2 ways of doing
let
, remember how in ghci must use let declare local variables, can same indo
block.let somemonad = dosomething
- notice, no
in
- notice, no
- monad transformers! big topic explain in blurb, they're monads have special function
lift
can "lift" monad transformer. transformers end in t, eg statet. pretty every monad use has equivalent transformer.
Comments
Post a Comment