Haskell: actual IO monad implementation, in different language?

后端 未结 7 965
梦如初夏
梦如初夏 2020-12-08 08:24

How is IO monad actually implemented?in sense of, what would be the actual implementation of the main function?

How would I call haskell function (IO) f

7条回答
  •  自闭症患者
    2020-12-08 09:03

    In fact "IO a" is just "() -> a" in an impure language (where functions can have side effect). Let's say you want to implement IO in SML :

    structure Io : MONAD =
    struct
      type 'a t = unit -> 'a
      return x = fn () => x
      fun (ma >>= g) () = let a = ma ()
                          in g a ()
      executeIo ma = ma ()
    end
    

提交回复
热议问题