[Haskell-cafe] Dynamic choice of "reverse" implementation

Brian Hulley brianh at metamilk.com
Fri Sep 28 12:54:23 EDT 2007

Krzysztof Kościuszkiewicz wrote:
> So the type of mapM_ used in the code is
> (Foldable t, Monad m) => (a -> m b) -> t a -> m ()
> I'd like to keep the generic Foldable t there when "m" is specialized to IO.
> I thought this would allow type of "reversor" to be specialized to
> (Foldable f) => [String] -> f String
> ... I'd like to avoid [a] -> something -> [a]

Yes this type should be fine. To implement reversor though you'd still 
need to first convert from the concrete list to whatever foldable you're 
using, before reversing the foldable, or implement something more 
general eg:

     reversor :: (Foldable f, Foldable g) :: f a -> g a

Of course with lazy evaluation + compiler optimizations the lists in [a] 
-> something -> [a] should be erased at compile time... ;-)

Regards, Brian.

More information about the Haskell-Cafe mailing list