Ich habe eine theoretische Frage über die Art eines Typs, der in viele Beispiele verwendet wird, die das Coyoneda-Lemma erklären. Sie werden normalerweise als "natürliche Transformationen" bezeichnet, die meines Wissens Abbildungen zwischen Funktoren sind. Was mich verwirrt ist, dass sie in diesen Beispielen manchmal von Set
zu einem Funktor F
mappen. Es ist also nicht wirklich eine Zuordnung zwischen Funktoren, sondern etwas entspannteres. HierSind die "natürlichen Transformationen", die wir auf Coyoneda anwenden, um einen Functor tatsächlich "natürliche Transformationen" zu bekommen?
ist der Code in Frage:
{-# LANGUAGE GADTs #-}
{-# LANGUAGE RankNTypes #-}
module Coyo where
import Data.Set (Set)
import qualified Data.Set as Set
data Coyoneda f a where
Coyoneda :: (b -> a) -> f b -> Coyoneda f a
instance Functor (Coyoneda f) where
fmap f (Coyoneda c fa) = Coyoneda (f . c) fa
set :: Set Int
set = Set.fromList [1,2,3,4]
lift :: f a -> Coyoneda f a
lift fa = Coyoneda id fa
lower :: Functor f => Coyoneda f a -> f a
lower (Coyoneda f fa) = fmap f fa
type NatT f g = forall a. f a -> g a
coyoset :: Coyoneda Set Int
coyoset = fmap (+1) (lift set)
applyNatT :: NatT f g -> Coyoneda f a -> Coyoneda g a
applyNatT n (Coyoneda f fa) = Coyoneda f (n fa)
-- Set.toList is used as a "natural transformation" here
-- while it conforms to the type signature of NatT, it
-- is not a mapping between functors `f` and `g` since
-- `Set` is not a functor.
run :: [Int]
run = lower (applyNatT Set.toList coyoset)
Was ich hier Missverständnis?
EDIT: Nach einer Diskussion über #haskell in freenode Ich denke, ich muss meine Frage ein wenig klären. Es ist im Grunde: "Was ist Set.toList
in einem kategorientheoretischen Sinn? Da ist es offensichtlich (?) Keine natürliche Transformation".
In der Injektiv-Unterkategorie ist sogar 'toList' eine natürliche Transformation. – leftaroundabout
Danke für die Antwort! Also 'n'' und' n' bilden hier ein Sektion/Retraction-Paar? – raichoo
@raichoo Ja, 'n' und' n'' sind eine ganze Familie von Abschnitt/Retraktions-Paaren, da 'n '. n == ID'. Nicht alle Abschnitte/Retraktions-Paare folgen dem stärkeren Gesetz 'n'. fmap f. n == fmap f'. – Cirdec