
On Fri, Sep 18, 2009 at 6:05 PM, Heinrich Apfelmus
Yusaku Hashimoto wrote:
- use Maybe as usual, we should use adapters as we need
Conor, You have said this many times elsewhere, but unfortunately, I heard it for the first time =) so please correct me if I'm wrong.
I thought generalizing lookup is good example for usage of the MonadPlus as I read in RWH[1], but you said it's not necessary.
Now, I understood there are two positions for such classes. One is using generalizing for it, another is not.
So, I want to know that when such classes should be used from later position.
Heinrich suggested that is for overloading.
To elaborate on generality versus overloading: the function
lookupM :: MonadPlus m => k -> Map k a -> m a
is not more general than
lookup :: k -> Map k a -> Maybe a
because you can implement the former with the latter
lookupM k = mop . lookup k
mop = maybe mzero return
In other words, lookupM doesn't introduce new functionality.
Rather, it gives you the syntactic convenience of not having to mention mop by overloading the result type. In other words, you can write
lookup = lookupM
or
lookupE :: k -> Map k a -> Either e a lookupE = lookupM
I got it. Thank you for explanation.
But do any other usages are exist?
I'm not quite sure I understand what you mean here?
I had misread the Conor's post like the raison d'etre of type classes was denied, so I asked how type class should be used. Thanks again. Cheers -nwn