[Haskell-cafe] Automatic Recognition of Functors

Walter Potter potter at southwestern.edu
Thu Mar 1 09:23:31 EST 2007


Given f:: a -> b it is very natural to lift f to P f :: P a -> P b  
where P is the power set functor. Or L f :: [a] -> [b].

We are modeling structures using repeated application of the power  
functor, via repeated application of [ ].

It would be very nice if Haskell would recognize this lifting. That  
is, if f :: a -> b then one automatically has f :: [a] -> [b]
without using fMap.

We can do something similar with classes in the following way:


class Addy a where
(+.) :: a -> a -> a

instance(Addy a) => Addy [ a]
(+.) w [ ] = w
(+.) [ ] w = w
(+.) (a:as) (b:bs) = (a+b) :(as + bs)

Now given

instance Addy Int
(+.) x y = x+y

One can compute
[[1,2],[3,4]] +. [ [2,3],[1,2,.3]].

I know I'm asking for a bit more here. I might need to use  fMap f :  
[ a] -> [ b].
But I can't seem to get by with
fMap f [[1,2],[3,4]] when f :: Int -> Int

We often need to lift functions to higher power maps.

It would be nice to have a way to do this with ease.

Suggestions are welcome.


More information about the Haskell-Cafe mailing list