haskell - Types and do notation -


this several questions rolled one:

  1. in do notation, each line have return same type? example, can write 1 line in single do block returns io monad, , returns integer? (my understanding, based on how de-sugaring >> , >>= seems work, answer no.)

  2. 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, given do block, each line must return?

  3. 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 of do block?

  1. in do-block, each line can return different types, must in same monad
    • one line can return io string , 1 can return io integer both have io.
  2. the same rest of haskell. type inference. in rest of haskell doesn't work, , when doesn't must annotate well.
  3. there 2 ways of doing
    • let, remember how in ghci must use let declare local variables, can same in do block. let somemonad = dosomething
      • notice, no in
    • 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

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -