6 ms·
Very understandable, type classes + inference + monads + do notation is quite a stack of unfamiliar machinery to understand all at once. The return type is inf
by gsg 9y ago
Very understandable, type classes + inference + monads + do notation is quite a stack of unfamiliar machinery to understand all at once.
The return type is inferred, and the type is what the type class machinery is driven by. You can get some more visibility into that by playing in ghci:
return 0 :: [Int] => [0]
return 0 :: Maybe Int => Just 0
Having behaviour driven by return type takes a bit of getting used to.
- moomin 9y agoReturn value polymorphism is hugely powerful though: it means you can write stuff that works for any Monad (involving return). Without it you can't sensibly do that.
- dllthomas 9y agoSure you can. It just involves a little more manual plumbing. Certainly less convenient, but not actually as bad as all that in the typical case.