lean4-htt/src/Init/Lean/Eval.lean
2019-12-11 06:19:12 -08:00

38 lines
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) 2019 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.Reader
import Init.System.IO
import Init.Lean.Environment
namespace Lean
universe u
/-- `HasEval` extension that gives access to the current environment & options.
The basic `HasEval` class is in the prelude and should not depend on these
types. -/
class MetaHasEval (α : Type u) :=
(eval : Environment → Options → α → IO Unit)
instance MetaHasEvalOfHasEval {α : Type u} [HasEval α] : MetaHasEval α :=
⟨fun env opts a => HasEval.eval a⟩
abbrev MetaIO := ReaderT (Environment × Options) IO
def MetaIO.getEnv : MetaIO Environment := do
ctx ← read; pure ctx.1
def MetaIO.getOptions : MetaIO Options := do
ctx ← read; pure ctx.2
instance MetaIO.metaHasEval : MetaHasEval (MetaIO Unit) :=
⟨fun env opts x => x (env, opts)⟩
instance MetaIO.monadIO : MonadIO MetaIO :=
⟨fun _ x _ => x⟩
end Lean