haskell - Types and do notation -
this several questions rolled one:
in
donotation, each line have return same type? example, can write 1 line in singledoblock returnsiomonad, , 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
iomonads. how know, givendoblock, each line must return?again assuming answer #1 no: how use functions don't return right kind of monad inside
doblock? 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 ofdoblock?
- in do-block, each line can return different types, must in same monad
- one line can return
io string, 1 can returnio integerboth 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 indoblock.let somemonad = dosomething- notice, no
in
- notice, no
- monad transformers! big topic explain in blurb, they're monads have special function
liftcan "lift" monad transformer. transformers end in t, eg statet. pretty every monad use has equivalent transformer.
Comments
Post a Comment