User loginNavigation 
Monads in various languages
While working on implementing monads and comprehensions, I ran into a complication in translating comprehensions to their underlying monadic expressions. Looking at other languages for insight, I realized that all languages which make use of monads use type deduction and that this feature appears to be critical to making comprehensions work.
To translate a comprehension for a monad M, you need to translate expressions like [x+1  x < xm] where you know that xm:M(int) for a statically unknown monad M. But how do you typecheck "x+1", which requires that x is a numeric type? Nothing in this expression explicitly indicates that x is numeric. Thus one would need type deduction and explicit universal quantification with matching to deduce that x is numeric, or ugly explicit type specification on comprehensions like [x+1  x::int < xm]. My conjecture is that this is why monads happen to be widelyused only in languages supporting HindleyMilner type deduction, while traditional languages use imperative constructs like iterators, exceptions and sideeffects for roughly similar tasks. Monads would be awfully inconvenient without this syntactic sugar, which happens to rely on a rather narrowlyavailable language feature. I would appreciate any counterarguments on this conjecture. Also any references to non HindleyMilner languages supporting monads conveniently. By Tim Sweeney at 20040929 23:05  LtU Forum  previous forum topic  next forum topic  other blogs  4854 reads

Browse archivesActive forum topics 
Recent comments
1 hour 29 min ago
7 hours 24 min ago
1 day 10 min ago
1 day 9 hours ago
1 day 20 hours ago
1 day 21 hours ago
1 day 21 hours ago
1 day 22 hours ago
1 day 22 hours ago
2 days 1 hour ago