[Haskell-cafe] Re: Generalizing takeWhile

yairchu at gmail.com yairchu at gmail.com
Thu Jul 23 09:13:46 EDT 2009


On Jul 22, 7:44 pm, Felipe Lessa <felipe.le... at gmail.com> wrote:
> > type TypeOfF a = a -> Maybe (TypeOfF' a)
> > newtype TypeOfF' a = F {unF :: TypeOfF a}

An interesting observation is that "ListT ((->) a) ()" would also do
the job.
If one would want to also generalize "filter" this way,
a more appropriate type would be "ListT ((->) a) Bool",
which could still be used for the generalized takeWhile, dropWhile,
etc.

You need to import Control.Monad.Reader for the Monad instance of "(-
>) a".
ListT here isn't the one from mtl, but rather the one from "http://
www.haskell.org/haskellwiki/ListT_done_right"
or from the "generator" package in hackage.


More information about the Haskell-Cafe mailing list