Many functions can be generalised
Henning Thielemann
lemming at henning-thielemann.de
Tue Nov 29 07:34:02 UTC 2016
On Sun, 27 Nov 2016, amindfv at gmail.com wrote:
> I'd also be -1. Function generalization sometimes has a cost in
> comprehensability, and there aren't enough benefits to make it worth it
> to me.
And you lose type inference in more cases.
> > maybeToList :: Foldable f => f a -> [a]
> > maybeToList = toList
Why should we have two names for Foldable.toList, where maybeToList even
is no longer special to Maybe?
> > take :: Int -> (forall f a. Foldable f => f a -> [a])
> > take n = toListOf (taking n folded)
>
> > drop :: Int -> (forall f a. Foldable f => f a -> [a])
> > drop n = toListOf (dropping n folded)
>
> > cycle :: Foldable f => f a -> [a]
> > cycle = toListOf (cycled folded)
I'd prefer an extension to Monoid, i.e.
take :: (??? m) => Int -> m -> m
drop :: (??? m) => Int -> m -> m
cycle :: (Semigroup m) => m -> m
Yet, I do not propose to replace Prelude functions by this
generalisations.
More information about the Libraries
mailing list