|
Subject: Curious Functor Class Newsgroups: gmane.comp.lang.haskell.cafe Date: 2006-09-26 08:03:59 GMT (2 years, 40 weeks, 3 days, 3 hours and 53 minutes ago)
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
|
|
|