[Haskell-cafe] Curious Functor Class

Ashley Yakeley ashley at semantic.org
Tue Sep 26 04:03:59 EDT 2006


Is there anything useful about the class of functors which foralls can 
move across? In other words, functors f, for which for any function g 
there is this isomorphism

  f (forall a. g a) <=> forall a. f (g a)

In this Haskell snippet I've called the class Hoistable and the 
isomorphism is (hoist,unhoist):

  newtype All g = MkAll (forall a. g a);

  class (Functor f) => Hoistable f where
  {
    hoist :: forall g. (f (All g) -> (forall a. f (g a)));
    hoist = fmap (\(MkAll ga) -> ga);

    unhoist :: forall g. ((forall a. f (g a)) -> f (All g));
  };

Functors that can be made instances of Hoistable:

  data Singleton a = MkSingleton
  newtype Identity a = MkIdentity a
  (->) p -- forall p.
  data Pair a = MkPair a a
  data Extra p a = MkExtra p a -- forall p.
  data Compose p q a = MkCompose (p (q a))
    -- forall p q. (Hoistable p,Hoistable q) =>

On the other hand, Maybe and Either cannot. The key seems to be in only 
having one "form", i.e. no "|"s in the definition. Does this class 
actually have a use, or is it merely a curiosity?

-- 
Ashley Yakeley
Seattle WA



More information about the Haskell-Cafe mailing list