Applicative and Functor
Ross Paterson
ross at soi.city.ac.uk
Mon Mar 6 18:04:09 EST 2006
On Mon, Mar 06, 2006 at 12:36:01PM -0800, Ashley Yakeley wrote:
> 3. Making Functor and Foldable superclasses of Traversable, and getting
> rid of fmapDefault and foldMapDefault.
If you have the superclasses, the defaults are more useful, for people
who only want to define Traversable.
> You might also consider:
>
> 4. Adding a method to "class Traversable t" (with a default implementation):
>
> toList :: t a -> [a]
It's in Data.Foldable, but as a function, not a method:
toList :: Foldable t => t a -> [a]
#ifdef __GLASGOW_HASKELL__
toList t = build (\ c n -> foldr c n t)
#else
toList = foldr (:) []
#endif
> 5. Renaming pure as returnA and <*> as apA. Only it looks like your
> Arrows stole returnA.
I rather like <*>, which comes from Doaitse Swierstra's parsing
combinators.
> If Functor is a superclass of Traversable, is it better to have traverse
> and mapM as the methods, or sequence and sequenceA?
sequence(A) would be the categorical way, but it's often more efficient
to define traverse/mapM, particularly for non-regular types.
> What's your "instance Applicative []"? Does it use repeat and zapp, or
> is it the "list of successes" (which would be compatible with "instance
> Monad []")?
It matches the monad instance. There's a newtype ZipList for the other one.
More information about the Libraries
mailing list