How is IO monad actually implemented?in sense of, what would be the actual implementation of the main function?
main
How would I call haskell function (IO) f
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