|
|
|
|
|
by harshavr
5968 days ago
|
|
If I remember correctly, there was a more tricky problem in implementing monads without the type system - sometimes which monad is chosen for an expression, depends not just on the arguments, but the expected type of the result. Ex : "return 3" might be [3] or an IO action with result 3. The compiler decides this based on the surrounding context. In dynamical languages one would have to manually specify which kind of 'return' you mean. This surrounding context inference feature, which is useful for type classes other than monads, has the unusual consequence that you need to specify more typeinfo in a dynamic language. |
|
Unlike haskell which can choose an implementation based on the return type of return and bind, you do have to spell it out. The macro with-monad will wrap a set of expressions up in the correct monad, and the domonad monad comprehension form is also able to accept an optional monad name (useful if you aren't inside a with-monad form, or if you need a different monad)