#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Options

# Question 2.2 - Constant functors

edited January 19

Constant functors.

Let $$C$$ and $$D$$ be categories. Given any object $$d$$ in $$D$$, we can define the constant functor $$K_d: C \rightarrow D$$ on $$d$$. This functor sends every object $$C$$ to $$d \in Ob\ D$$, and every morphism of $$C$$ to the identity morphism on $$d$$.

(a) Take the set $$B$$ = {$$T,F$$}. Show that the constant functor $$K_B: Set \rightarrow Set$$ obeys the two functor laws: preservation of composition and preservation of identities.

(b) Implement in Haskell the constant functor on the type Bool.

• Options
1.
edited January 25

In b: am confused by what it means by "the constant functor" aren't there two constant functors?

Edit: I was confused because we went from a constant functor from Set_Bool -> Set_Bool to a constant functor from Type -> Type. I get now that the constant that they are looking for is the $$Bool \in Obj_{Hask}$$

Comment Source:> In b: am confused by what it means by "the constant functor" aren't there two constant functors? Edit: I was confused because we went from a constant functor from Set_Bool -> Set_Bool to a constant functor from Type -> Type. I get now that the constant that they are looking for is the \$$Bool \in Obj_{Hask} \$$
• Options
2.

I just noticed this was written in "draft" and I had forgotten to post it :P

newtype ConstF c a = Const c

instance Functor (ConstF c) where

fmap f (Const c) = Const c

kb :: ConstF Bool a

kb = ConstF True

-- fmap id (Const c) = id (Const c)

-- Const c = Const c <-- applying the definition of fmap

-- fmap (f.g) (Const c) = (fmap f . fmap g) (Const c)

-- Const c = fmap f (fmap g (Const c)) <<- applying the definition of fmap on the left side

-- Const c = fmap f (Const c) <-- applying the definition of fmap on the right side

-- Const c = Const c

Comment Source:I just noticed this was written in "draft" and I had forgotten to post it :P > newtype ConstF c a = Const c > instance Functor (ConstF c) where > fmap f (Const c) = Const c > kb :: ConstF Bool a > kb = ConstF True > -- fmap id (Const c) = id (Const c) > -- Const c = Const c <-- applying the definition of fmap > -- fmap (f.g) (Const c) = (fmap f . fmap g) (Const c) > -- Const c = fmap f (fmap g (Const c)) <<- applying the definition of fmap on the left side > -- Const c = fmap f (Const c) <-- applying the definition of fmap on the right side > -- Const c = Const c 
• Options
3.
edited February 1

Proof (a).

$$K_B$$ is the claimed constant functor which maps every set to $$B$$ and every morphism to $$Id_B$$.

To prove that $$K_B$$ is indeed a functor, it suffices to show that for all sets $$S$$, the mapping $$K_S$$ satisfies the two functor laws.

The identity law for $$K_S: Set \rightarrow Set$$ says that for every $$A \in Ob(Set)$$, we have that $$K_S(Id_A) = Id_{K_S(A)}$$. Since $$K_S(A) = S$$, this requirement restates to $$K_S(Id_A) = Id_S$$. This is certainly true, as $$K_S$$ maps any morphism whatsoever to $$Id_S$$.

The composition law requires that for composable morphisms $$f, g$$, we have that $$K_S(f \triangleright g) = K_S(f) \triangleright K_S(g)$$. That's equivalent to saying that $$Id_S = Id_S \triangleright Id_S$$, which is an axiomatic fact.

Comment Source:Proof (a). \$$K_B\$$ is the claimed constant functor which maps every set to \$$B\$$ and every morphism to \$$Id_B\$$. To prove that \$$K_B\$$ is indeed a functor, it suffices to show that for all sets \$$S\$$, the mapping \$$K_S\$$ satisfies the two functor laws. The identity law for \$$K_S: Set \rightarrow Set\$$ says that for every \$$A \in Ob(Set)\$$, we have that \$$K_S(Id_A) = Id_{K_S(A)}\$$. Since \$$K_S(A) = S\$$, this requirement restates to \$$K_S(Id_A) = Id_S\$$. This is certainly true, as \$$K_S\$$ maps any morphism whatsoever to \$$Id_S\$$. The composition law requires that for composable morphisms \$$f, g\$$, we have that \$$K_S(f \triangleright g) = K_S(f) \triangleright K_S(g)\$$. That's equivalent to saying that \$$Id_S = Id_S \triangleright Id_S\$$, which is an axiomatic fact.