Closed wdanilo closed 8 years ago
I don't see how this is useful, and overlapping instances scare me.
Oh, I think we can discuss it further here. Imagine a record, which has "default" instance, but its default instance can be constructed only when it has access to some monadic stack (it wants for example access GraphBuilder
if it is a Node
). Then we can just use defaultM
here. @mauke why it scares you? I didn't expected such answer to be honest because OverlappingInstances
are rather widely used ...
In new GHC we can of course use the instance-specific {-# OVERLAPPABLE #-}
pragma, which will affect ONLY this instance. Even better - in new GHC we don't have to use any pragma, because we can control it in the files when we use it.
@fizruk: please see my explanation above. I didn't saw your answer then, I'm sorry for that! :) In fact the "default" instance provided in the code could be implemented as default method as well, I mean:
class DefaultM m a where
-- | The default value for this type in a monad.
defM :: m a
default defM :: (Monad m, Default a) => m a
defM = return def
and in fact it is much better than my original proposition - without any overlapping instances enabled. @mauke would it be ok for you?
I still don't see how this is useful. I haven't run into a problem where I would need it, so it's hard for me to judge whether this would be a good thing.
In the meantime, if you need this, can't you release it as a separate module? AFAICS there's no technical need for it to be in Data.Default
itself.
@mauke: Of course I can, it just fits perfectly into this module. This is just default instance of a datatype, that can be generated in a monad, that's all. Releasing milions of small modules that provide very similar things for different use cases is a little bit strange, but I can release something like data-default-plus
(or something with another name) which will reexport things from data-default
with additional classes.
Why would you need this specific class? Perhaps an explicit use case might be of help here.
This particular interface can be replaced easily with a
newtype
:BTW, in presence of AMP we can replace
Monad
withApplicative
andreturn
withpure
.