Modules

categorical-crypto

  • Prelude

CategoricalCrypto

  • CategoricalCrypto
  • Abstract
  • Abstract2
  • Abstract2.Equivalence
  • Abstract2.Morphism
  • Abstract2.OAPEmulation
  • Abstract2.WideSubcategory
  • Channel.Category
  • Channel.Core
  • Channel.Selection
  • Examples.Basic
  • Examples.Commitment
  • Examples.RelSetup
  • Examples.Signatures
  • FamilyCategory
  • Machine.Constraints
  • Machine.Core
  • MachineAxioms
  • RandomOracle
  • RandomOracle2
  • SFunM
  • Standard
  • Standard2
  • Standard2.Morphism
  • StandardTV
  • UCSetup
  • UCSetup.Morphism
  • VanishingTV

Categories

  • Actegory
  • Actegory.Underlying
  • Category.EquivClosureHelper
  • Coherence.Monoidal
  • Coherence.Monoidal.Compare
  • Coherence.Monoidal.Diagram
  • Coherence.Monoidal.Frontend
  • Coherence.Monoidal.Frontend.Core
  • Coherence.Monoidal.Frontend.Sigma
  • Coherence.Monoidal.MacLane
  • Coherence.Monoidal.Normalize
  • Coherence.Monoidal.Reflect
  • Coherence.Monoidal.Sigma
  • Coherence.Monoidal.Test.Frontend
  • Coherence.Monoidal.Test.InterchangeStress
  • Coherence.Monoidal.Test.Limitations
  • Coherence.Monoidal.Test.SigmaFrontend
  • Coherence.Monoidal.WireCoherence
  • CoherenceIsos
  • Diagram.Coend.Ext.Setoids
  • Discrete
  • FreeMonoidal
  • FreeStrictMonoidal
  • Functor.Monoidal.CurriedTensor
  • Functor.Monoidal.CurriedTensor.Properties
  • Functor.Monoidal.Properties.Ext
  • Functor.Presheaf.Morphism
  • GradedKleisli
  • GradedKleisli.Functorial
  • GradedKleisli.Functorial.Category
  • GradedKleisli.Regrade
  • KernelCongruence
  • KernelCongruence.Reindex
  • LocallyGraded
  • LocallyGraded.FreeActegory
  • LocallyGraded.FreeActegory.Kleisli
  • LocallyGraded.Kleisli
  • Monad.Graded.Ext
  • Monad.Graded.Morphism
  • Monad.Graded.Pullback
  • Monad.Graded.Uncurried
  • Morphism.Reasoning.Ext
  • NaturalTransformationHelper
  • Properties

Class

  • Monad.Ext

Data

  • List.Properties.Ext
  • Maybe.Ext
  • Nat.Poly

LibExt

  • LibExt
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
{-# OPTIONS --safe --without-K #-}
 
open import Meta.Prelude
 
open import Class.Functor
open import Class.Applicative
open import Class.Monad
open import Reflection using (TC; ErrorPart; typeError; catchTC; strErr)
 
module Class.MonadError where
 
private variable e f : Level
 
record MonadError (E : Set e) (M : ∀ {f} → Set f → Set f) : Setω where
field
error : E → M A
catch : M A → (E → M A) → M A
 
instance
Alternative-M : Alternative M
Alternative-M = record { _<|>_ = λ x y → catch x (λ _ → y) }
 
open MonadError
 
MonadError-TC : MonadError (List ErrorPart) TC
MonadError-TC .error = typeError
MonadError-TC .catch x h = catchTC x (h [ strErr "TC doesn't provide which error to catch" ])
 
ErrorT : (E : Set) → (M : ∀ {f} → Set f → Set f) → ∀ {f} → Set f → Set f
ErrorT E M A = M (E ⊎ A)
 
import Data.Sum as Sum
 
module _ {E : Set} {M : ∀ {a} → Set a → Set a} where
 
Functor-ErrorT : ⦃ _ : Functor M ⦄ → Functor (ErrorT E M)
Functor-ErrorT ._<$>_ f = fmap (Sum.map₂ f)
 
instance _ = Functor-ErrorT
 
Applicative-ErrorT : ⦃ _ : Applicative M ⦄ → Applicative (ErrorT E M)
Applicative-ErrorT .pure a = pure (inj₂ a)
Applicative-ErrorT ._<*>_ f x = _<*>_ {F = M} (fmap go f) x
where
go : (E ⊎ (A → B)) → (E ⊎ A) → (E ⊎ B)
go = λ where
(inj₁ e) _ → inj₁ e
_ (inj₁ e) → inj₁ e
(inj₂ f) (inj₂ a) → inj₂ (f a)
 
instance _ = Applicative-ErrorT
 
Monad-ErrorT : ⦃ _ : Monad M ⦄ → Monad (ErrorT E M)
Monad-ErrorT .return a = return (inj₂ a)
Monad-ErrorT ._>>=_ x f = x >>= λ where
(inj₁ e) → return (inj₁ e)
(inj₂ a) → f a
 
instance _ = Monad-ErrorT
 
MonadError-ErrorT : ⦃ _ : Monad M ⦄ → MonadError E (ErrorT E M)
MonadError-ErrorT .error e = return (inj₁ e)
MonadError-ErrorT .catch x h = x >>= Sum.[ h , return ]