Derivative.agda 653 B

12345678910111213141516171819202122232425
  1. module Derivative where
  2. open import Sets
  3. open import Functor
  4. import Isomorphism
  5. ∂ : U -> U
  6. ∂ (K A) = K [0]
  7. ∂ Id = K [1]
  8. ∂ (F + G) = ∂ F + ∂ G
  9. ∂ (F × G) = ∂ F × G + F × ∂ G
  10. open Semantics
  11. -- Plugging a hole
  12. plug-∂ : {X : Set}(F : U) -> ⟦ ∂ F ⟧ X -> X -> ⟦ F ⟧ X
  13. plug-∂ (K _) () x
  14. plug-∂ Id <> x = x
  15. plug-∂ (F + G) (inl c) x = inl (plug-∂ F c x)
  16. plug-∂ (F + G) (inr c) x = inr (plug-∂ G c x)
  17. plug-∂ (F × G) (inl < c , g >) x = < plug-∂ F c x , g >
  18. plug-∂ (F × G) (inr < f , c >) x = < f , plug-∂ G c x >