lean4-htt/Lake/Build/IO.lean
tydeu ec8b351445 refactor: generalize some IO-related code
* add `def OptionIO := EIO PUnit`
* add `OptionIOTask` for `OptionIO`
* rename `BuildCoreM` -> `BuildIO`
* rename `Util.LogT` ->  `Util.Log`
* generalize `error` to `MonadError`
* generalize` Cli.build`
2021-11-25 03:22:11 -05:00

27 lines
796 B
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) 2021 Mac Malone. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mac Malone
-/
import Lake.Util.Log
import Lake.Util.Error
import Lake.Util.OptionIO
namespace Lake
abbrev BuildIO :=
LogMethodsT BaseIO OptionIO
namespace BuildIO
def run (logMethods : LogMethods BaseIO) (self : BuildIO α) : IO α :=
ReaderT.run self logMethods |>.toIO fun _ => IO.userError "build failed"
def runWith (logMethods : LogMethods BaseIO) (self : BuildIO α) : OptionIO α :=
ReaderT.run self logMethods
instance : MonadError BuildIO := ⟨MonadLog.error⟩
instance : MonadLift IO BuildIO := ⟨MonadError.runIO⟩
instance : MonadLift (LogT IO) BuildIO where
monadLift x := fun meths => liftM (n := BuildIO) (x.run meths.lift) meths