|
|
|
|
|
by mbrubeck
5970 days ago
|
|
That's like saying arithmetic doesn't work in dynamic languages because nothing stops you from writing (+ 42 "foo"). Sure, you won't get a compiler error - that's why it's a dynamic language! - but you will get an error at runtime. What "stops" you from writing broken code are automated tests, lint checkers, discipline, and common sense. I say this as someone who has implemented monadic code in both JavaScript and Haskell, including a small homegrown parser combinator module: http://limpet.net/mbrubeck/2009/10/30/compleat.html |
|
Having also implemented a monad library in a dynamically-typed language, I am well aware of what happens when one operand of bind returns the wrong type. The rest of the computation silently proceeds with that type, until it happens to change again. This results in a subtle loss of information, rather than outright failure.
Like I said, programming with combinators is a great way to reuse code -- but not all combinators that are of type "f a -> (a -> g b) -> g b" are monadic. It's only a monad when f = g.