chore: Id missing instances
This commit is contained in:
parent
ebc166585a
commit
d7d7e16f96
3 changed files with 19 additions and 7 deletions
|
|
@ -13,23 +13,27 @@ universe u
|
|||
|
||||
def Id (type : Type u) : Type u := type
|
||||
|
||||
@[inline] def Id.pure {α : Type u} (x : α) : Id α :=
|
||||
namespace Id
|
||||
|
||||
@[inline] protected def pure {α : Type u} (x : α) : Id α :=
|
||||
x
|
||||
|
||||
@[inline] def Id.bind {α β : Type u} (x : Id α) (f : α → Id β) : Id β :=
|
||||
@[inline] protected def bind {α β : Type u} (x : Id α) (f : α → Id β) : Id β :=
|
||||
f x
|
||||
|
||||
@[inline] def Id.map {α β : Type u} (f : α → β) (x : Id α) : Id β :=
|
||||
@[inline] protected def map {α β : Type u} (f : α → β) (x : Id α) : Id β :=
|
||||
f x
|
||||
|
||||
instance Id.hasBind : HasBind Id :=
|
||||
instance : HasBind Id :=
|
||||
{ bind := @Id.bind }
|
||||
|
||||
instance Id.monad : Monad Id :=
|
||||
instance : Monad Id :=
|
||||
{ pure := @Id.pure, bind := @Id.bind, map := @Id.map }
|
||||
|
||||
@[inline] def Id.run {α : Type u} (x : Id α) : α :=
|
||||
@[inline] protected def run {α : Type u} (x : Id α) : α :=
|
||||
x
|
||||
|
||||
instance : MonadRun id Id :=
|
||||
⟨@Id.run⟩
|
||||
|
||||
end Id
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ prelude
|
|||
import Init.Data.String.Basic
|
||||
import Init.Data.UInt
|
||||
import Init.Data.Nat.Div
|
||||
import Init.Control.Id
|
||||
open Sum Subtype Nat
|
||||
|
||||
universes u v
|
||||
|
|
@ -23,6 +24,9 @@ inferInstanceAs (HasRepr α)
|
|||
instance : HasRepr Bool :=
|
||||
⟨fun b => cond b "true" "false"⟩
|
||||
|
||||
instance {α} [HasRepr α] : HasRepr (Id α) :=
|
||||
inferInstanceAs (HasRepr α)
|
||||
|
||||
instance {p : Prop} : HasRepr (Decidable p) :=
|
||||
⟨fun h => match h with
|
||||
| Decidable.isTrue _ => "true"
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import Init.Data.String.Basic
|
|||
import Init.Data.UInt
|
||||
import Init.Data.Nat.Div
|
||||
import Init.Data.Repr
|
||||
import Init.Control.Id
|
||||
open Sum Subtype Nat
|
||||
|
||||
universes u v
|
||||
|
|
@ -18,7 +19,10 @@ class HasToString (α : Type u) :=
|
|||
export HasToString (toString)
|
||||
|
||||
-- This instance is needed because `id` is not reducible
|
||||
instance {α : Type u} [HasToString α] : HasToString (id α) :=
|
||||
instance {α} [HasToString α] : HasToString (id α) :=
|
||||
inferInstanceAs (HasToString α)
|
||||
|
||||
instance {α} [HasToString α] : HasToString (Id α) :=
|
||||
inferInstanceAs (HasToString α)
|
||||
|
||||
instance : HasToString String :=
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue