ekmett / kan-extensions

Kan extensions, Kan lifts, the Yoneda lemma, and (co)monads generated by a functor
Other
78 stars 33 forks source link

Pattern synonyms for different encodings of Day convolution #36

Open Icelandjack opened 7 years ago

Icelandjack commented 7 years ago

It's possible to encode Day differently:

data Day2__ :: (Type -> Type) -> (Type -> Type) -> (Type -> Type) where
  Day2__ :: f xx -> g (xx -> a) -> (Day2__ f g) a

data Day3__ :: (Type -> Type) -> (Type -> Type) -> (Type -> Type) where
  Day3__ :: f (xx -> a) -> g xx -> (Day3__ f g) a

Users might want access to them for some reason, we can expose pattern synonyms to access them

day2 :: forall f g a. Functor g => Day f g a -> Day2__ f g a
day2 (Day fa gb f) = Day2__ fa (flip f gb)

day3 :: Functor f => Day f g a -> Day3__ f g a
day3 (Day fa gb f) = Day3__ (fmap f fa) gb 

pattern Day2 :: forall f g a. Functor g => forall xx. f xx -> g (xx -> a) -> Day f g a
pattern Day2 fa gb <- (day2 -> Day2__ fa gb)
  where Day2 fa gb = Day fa gb (&)

pattern Day3 :: forall f g a. Functor f => forall xx. f (xx -> a) -> g xx -> Day f g a
pattern Day3 fa gb <- (day3 -> Day3__ fa gb)
  where Day3 fa gb = Day fa gb id

Useful or not? I didn't put thought into choosing encodings or names.