-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update most of existing code to new ITree
- Loading branch information
Showing
12 changed files
with
262 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import LeanBoogie.ITree.ITree | ||
|
||
namespace ITree | ||
|
||
/- | ||
# Events | ||
-/ | ||
|
||
instance (priority := low) : OfNat (Type -> Type) n where ofNat := fun _ => Fin n | ||
instance : OfNat (Type -> Type) 0 where ofNat := fun _ => PEmpty | ||
instance : OfNat (Type -> Type) 1 where ofNat := fun _ => PUnit | ||
|
||
/-- The union of two event types. -/ | ||
inductive EvProd (E₁ E₂ : Type -> Type) : Type -> Type | ||
| left : E₁ X -> EvProd E₁ E₂ X | ||
| right : E₂ X -> EvProd E₁ E₂ X | ||
|
||
instance : HAdd (Type -> Type) (Type -> Type) (Type -> Type) := ⟨EvProd⟩ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import LeanBoogie.ITree.ITree | ||
import LeanBoogie.ITree.Monad | ||
|
||
namespace ITree | ||
|
||
/- | ||
## ITrees form an *iterative* monad | ||
-/ | ||
|
||
|
||
/-- Repeat a computation until it returns `B`. | ||
From the ITrees paper, page 12: | ||
``` | ||
CoFixpoint iter (body : A → itree E (A + B)) : A → itree E B := | ||
fun a ⇒ ab <- body a ;; | ||
match ab with | ||
| inl a ⇒ Tau (iter body a) | ||
| inr b ⇒ Ret b | ||
end. | ||
``` -/ | ||
def iter (body : A -> ITree E (A ⊕ B)) (a₀ : A) : ITree E B := sorry -- TODO | ||
-- ITree.corec (fun (x : A ⊕ ITree E (B)) => | ||
-- match x with | ||
-- | .inl a => | ||
-- -- Run the body, if it returned `a` we iter again, if it returned `b` we are done. | ||
-- let res : ITree E (A ⊕ B) := bind (body a) (fun ab => | ||
-- match ab with | ||
-- | .inl a => .ret (.inl a) | ||
-- | .inr b => .ret (.inr b) | ||
-- ) | ||
-- match res.dest with | ||
-- -- | .ret (a : A ⊕ B) => .ret sorry | ||
-- | .ret (.inl a) => .tau (.inl a) -- call `iter body a` | ||
-- | .ret (.inr b) => .ret b -- we are done | ||
-- | .tau (t : ITree E _) => .tau (.inr t) | ||
-- | .vis e k => sorry | ||
-- | .inr b => Base.replay b .inr | ||
-- ) (Sum.inl a₀) | ||
|
||
theorem iter_fp {f : A -> ITree E (A ⊕ B)} | ||
: iter f a₀ = do let ab <- f a₀ | ||
match ab with | ||
| .inl a => (iter f a) | ||
| .inr b => return b | ||
:= by sorry | ||
|
||
/-- | ||
Definition loop (body : C + A → itree E (C + B)) : A → itree E B := | ||
fun a ⇒ iter (fun ca ⇒ | ||
cb <- body ca ;; | ||
match cb with | ||
| inl c ⇒ Ret (inl (inl c)) | ||
| inr b ⇒ Ret (inr b) | ||
end) (inr a). | ||
-/ | ||
def loop (body : Sum C A -> ITree E (Sum C B)) (a : A) : ITree E B := sorry | ||
|
||
def iter_lift (body : A -> ITree E (A ⊕ B)) : (A ⊕ B) -> ITree E (A ⊕ B) := | ||
fun | .inl a => body a | .inr b => return .inr b |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import LeanBoogie.ITree.ITree | ||
|
||
namespace ITree | ||
|
||
/- | ||
# ITrees form a monad | ||
-/ | ||
|
||
def pure (a : A) : ITree E A := .ret a | ||
|
||
def bind (ta : ITree E A) (tb : A -> ITree E B) : ITree E B := sorry -- TODO: fix | ||
-- ITree.corec (β := Sum (ITree E A) (ITree E B)) (fun x => | ||
-- match x with | ||
-- | .inl ta => | ||
-- match ta.dest with | ||
-- | .ret (.up a : ULift A) => | ||
-- let tb : ITree E B := tb a | ||
-- let ret : ITree.Base E B (ITree E B) := tb.dest | ||
-- let ret : ITree.Base E B (ITree E A ⊕ ITree E B) := MvFunctor.map (F := TypeFun.ofCurried (n := _) Base) Base.Inr ret | ||
-- ret | ||
-- | .tau t => .tau (.inl t) | ||
-- | .vis e k => .vis e (fun x => .inl (k x)) | ||
-- | .inr b => Base.replay b Sum.inr | ||
-- ) (Sum.inl ta) | ||
|
||
instance : Monad (ITree E) where | ||
pure := pure | ||
bind := bind | ||
|
||
instance : LawfulFunctor (ITree E) where | ||
map_const := sorry | ||
id_map := sorry | ||
comp_map := sorry | ||
|
||
instance : LawfulMonad (ITree E) where | ||
seqLeft_eq := sorry | ||
seqRight_eq := sorry | ||
pure_seq := sorry | ||
bind_pure_comp := sorry | ||
bind_map := sorry | ||
pure_bind := sorry | ||
bind_assoc := sorry |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.