lean4-htt/library/init/control/Applicative.lean
2019-03-21 15:06:44 -07:00

34 lines
1.1 KiB
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/-
Copyright (c) 2016 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura, Sebastian Ullrich
-/
prelude
import init.control.functor
open Function
universes u v
class HasPure (f : Type u → Type v) :=
(pure {} {α : Type u} : α → f α)
export HasPure (pure)
class HasSeq (f : Type u → Type v) : Type (max (u+1) v) :=
(Seq : Π {α β : Type u}, f (α → β) → f α → f β)
infixl ` <*> `:60 := HasSeq.Seq
class HasSeqLeft (f : Type u → Type v) : Type (max (u+1) v) :=
(seqLeft : Π {α β : Type u}, f α → f β → f α)
infixl ` <* `:60 := HasSeqLeft.seqLeft
class HasSeqRight (f : Type u → Type v) : Type (max (u+1) v) :=
(seqRight : Π {α β : Type u}, f α → f β → f β)
infixl ` *> `:60 := HasSeqRight.seqRight
class Applicative (f : Type u → Type v) extends Functor f, HasPure f, HasSeq f, HasSeqLeft f, HasSeqRight f :=
(map := λ _ _ x y, pure x <*> y)
(seqLeft := λ α β a b, const β <$> a <*> b)
(seqRight := λ α β a b, const α id <$> a <*> b)