Re:A Bit of Heresy: Functional Languages are Overrated
by cageface on Tuesday June 29, 2010 @06:58PM
(#1473204)
So what do I do if I want to write a function that takes another function as a parameter, and some of the possible functions use Maybe and some use Either? What would this code look like?
[ Parent
| on HN ]
Re:A Bit of Heresy: Functional Languages are Overrated
by yummyfajitas on Wednesday June 30, 2010 @12:36AM
(#1473922)
f: (a -> m b) -> ... -> m Result
Maybe and Either are both monads and by convention Left errCode is the fail method of the Either monad. This will work exactly as you think it should. It will also work with, e.g., io actions that might fail.
Re:A Bit of Heresy: Functional Languages are Overrated
by naradaellis on Tuesday June 29, 2010 @08:17PM
(#1473379)
If I understand you correctly, such a possibility can never arise in Haskell's type system. A possible function would be (a -> Maybe b) -> a -> b, and this won't accept anything that returns an Either.