Skip to content

Instantly share code, notes, and snippets.

@vikraman
Created January 4, 2016 06:41
Show Gist options
  • Save vikraman/607573e6669183451929 to your computer and use it in GitHub Desktop.
Save vikraman/607573e6669183451929 to your computer and use it in GitHub Desktop.
Yoneda and CoYoneda
{-# OPTIONS --type-in-type #-}
module Yoneda where
_∘_ : {a b c : Set} → (b → c) → (a → b) → (a → c)
f ∘ g = λ z → f (g z)
record Functor (f : Set → Set) : Set where
field
map : {a b : Set} → (a → b) → f a → f b
Yoneda : (f : Set → Set) → (a : Set) → Set
Yoneda f a = {b : Set} → (a → b) → f b
YonedaFunctor : ∀ {f : Set → Set} → Functor (Yoneda f)
YonedaFunctor = record { map = λ f y → λ k → y (k ∘ f) }
data CoYoneda (f : Set → Set) (a : Set) : Set where
coyo : {b : Set} → (b → a) → f b → CoYoneda f a
CoYonedaFunctor : ∀ {f : Set → Set} → Functor (CoYoneda f)
CoYonedaFunctor = record { map = λ { f (coyo g v) → coyo (f ∘ g) v } }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment