Closed dcastro closed 4 years ago
I'm in favor of the addition. One tweak though: do we really need a separate newtype
for each typeclass? Couldn't a single newtype Monify f a = Monify (f a)
provide all the instances?
Note: Not actually recommending that name :)
Good point! I suppose that way we could also pass a Monify (Coll xs)
into a func :: (MonoFoldable m, MonoFunctor m) => ...
How about naming it ToMono
? Or maybe AsMono
?
EDIT: I feel inclined towards newtype ToMono f a = ToMono { fromMono :: f a }
I propose adding a newtype that generates a
MonoFoldable
instance for types that have aFoldable
instance.Use Case 1
A
that exports a collection data typeColl
with aFoldable
instance.Coll a
to a function from libraryB
that accepts only types withMonoFoldable
instances.At the moment, the only solution is to create an orphance instance
MonoFoldable (Coll a)
With the proposed newtype wrapper, I wouldn't need to create an orphan instance:
Use case 2
MonoFoldable
instancesMonoFoldable
instance, so I want to also give them the option of passing in a type with aFoldable
instanceWith the proposed newtype, I could provide both versions of
func
, without any code duplication, like so:Notes
The newtype's name (
FromFoldable
) is up for debate.I suppose the same rationale applies to:
Functor
->MonoFunctor
Traversable
->MonoTraversable
Applicative
->MonoPointed
If the owner/maintainers agree, I'd be happy to open a PR for this.