-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Mario Carneiro <[email protected]>
- Loading branch information
Showing
8 changed files
with
291 additions
and
8 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,40 @@ | ||
/- | ||
Copyright (c) 2024 Lean FRO, LLC. All rights reserved. | ||
Released under Apache 2.0 license as described in the file LICENSE. | ||
Authors: Kim Morrison | ||
-/ | ||
|
||
namespace EStateM | ||
|
||
namespace Result | ||
|
||
/-- Map a function over an `EStateM.Result`, preserving states and errors. -/ | ||
def map {ε σ α β : Type u} (f : α → β) (x : Result ε σ α) : Result ε σ β := | ||
match x with | ||
| .ok a s' => .ok (f a) s' | ||
| .error e s' => .error e s' | ||
|
||
@[simp] theorem map_ok {ε σ α β : Type u} (f : α → β) (a : α) (s : σ) : | ||
(Result.ok a s : Result ε σ α).map f = .ok (f a) s := rfl | ||
|
||
@[simp] theorem map_error {ε σ α β : Type u} (f : α → β) (e : ε) (s : σ) : | ||
(Result.error e s : Result ε σ α).map f = .error e s := rfl | ||
|
||
@[simp] theorem map_eq_ok {ε σ α β : Type u} (f : α → β) (x : Result ε σ α) (b : β) (s : σ) : | ||
x.map f = .ok b s ↔ ∃ a, x = .ok a s ∧ b = f a := by | ||
cases x <;> simp [and_assoc, and_comm, eq_comm] | ||
|
||
@[simp] theorem map_eq_error {ε σ α β : Type u} (f : α → β) (x : Result ε σ α) (e : ε) (s : σ) : | ||
x.map f = .error e s ↔ x = .error e s := by | ||
cases x <;> simp [eq_comm] | ||
|
||
end Result | ||
|
||
@[simp] theorem run_map (f : α → β) (x : EStateM ε σ α) : | ||
(f <$> x).run s = (x.run s).map f := rfl | ||
|
||
@[ext] theorem ext {ε σ α : Type u} (x y : EStateM ε σ α) (h : ∀ s, x.run s = y.run s) : x = y := by | ||
funext s | ||
exact h s | ||
|
||
end EStateM |
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,30 @@ | ||
/- | ||
Copyright (c) 2024 Lean FRO, LLC. All rights reserved. | ||
Released under Apache 2.0 license as described in the file LICENSE. | ||
Authors: Kim Morrison | ||
-/ | ||
import Batteries.Classes.SatisfiesM | ||
import Lean.Elab.Command | ||
|
||
/-! | ||
# Construct `LawfulMonad` instances for the Lean monad stack. | ||
-/ | ||
|
||
open Lean Elab Term Tactic Command | ||
|
||
instance : LawfulMonad (EIO ε) := inferInstanceAs <| LawfulMonad (EStateM _ _) | ||
instance : LawfulMonad BaseIO := inferInstanceAs <| LawfulMonad (EIO _) | ||
instance : LawfulMonad IO := inferInstanceAs <| LawfulMonad (EIO _) | ||
|
||
instance : LawfulMonad (EST ε σ) := inferInstanceAs <| LawfulMonad (EStateM _ _) | ||
|
||
instance : LawfulMonad CoreM := | ||
inferInstanceAs <| LawfulMonad (ReaderT _ <| StateRefT' _ _ (EIO Exception)) | ||
instance : LawfulMonad MetaM := | ||
inferInstanceAs <| LawfulMonad (ReaderT _ <| StateRefT' _ _ CoreM) | ||
instance : LawfulMonad TermElabM := | ||
inferInstanceAs <| LawfulMonad (ReaderT _ <| StateRefT' _ _ MetaM) | ||
instance : LawfulMonad TacticM := | ||
inferInstanceAs <| LawfulMonad (ReaderT _ $ StateRefT' _ _ $ TermElabM) | ||
instance : LawfulMonad CommandElabM := | ||
inferInstanceAs <| LawfulMonad (ReaderT _ $ StateRefT' _ _ $ EIO _) |
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,35 @@ | ||
/- | ||
Copyright (c) 2024 Lean FRO, LLC. All rights reserved. | ||
Released under Apache 2.0 license as described in the file LICENSE. | ||
Authors: Kim Morrison | ||
-/ | ||
import Batteries.Classes.SatisfiesM | ||
import Batteries.Lean.LawfulMonad | ||
import Lean.Elab.Command | ||
|
||
/-! | ||
# Construct `MonadSatisfying` instances for the Lean monad stack. | ||
-/ | ||
|
||
open Lean Elab Term Tactic Command | ||
|
||
instance : MonadSatisfying (EIO ε) := inferInstanceAs <| MonadSatisfying (EStateM _ _) | ||
instance : MonadSatisfying BaseIO := inferInstanceAs <| MonadSatisfying (EIO _) | ||
instance : MonadSatisfying IO := inferInstanceAs <| MonadSatisfying (EIO _) | ||
|
||
instance : MonadSatisfying (EST ε σ) := inferInstanceAs <| MonadSatisfying (EStateM _ _) | ||
|
||
instance : MonadSatisfying CoreM := | ||
inferInstanceAs <| MonadSatisfying (ReaderT _ <| StateRefT' _ _ (EIO _)) | ||
|
||
instance : MonadSatisfying MetaM := | ||
inferInstanceAs <| MonadSatisfying (ReaderT _ <| StateRefT' _ _ CoreM) | ||
|
||
instance : MonadSatisfying TermElabM := | ||
inferInstanceAs <| MonadSatisfying (ReaderT _ <| StateRefT' _ _ MetaM) | ||
|
||
instance : MonadSatisfying TacticM := | ||
inferInstanceAs <| MonadSatisfying (ReaderT _ $ StateRefT' _ _ TermElabM) | ||
|
||
instance : MonadSatisfying CommandElabM := | ||
inferInstanceAs <| MonadSatisfying (ReaderT _ $ StateRefT' _ _ (EIO _)) |
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,8 @@ | ||
import Batteries.Lean.SatisfiesM | ||
import Batteries.Data.Array.Monadic | ||
|
||
open Lean Meta Array Elab Term Tactic Command | ||
|
||
example (xs : Array Expr) : MetaM { ts : Array Expr // ts.size = xs.size } := do | ||
let r ← satisfying (xs.size_mapM inferType) | ||
return r |