lean4-htt/Lake/Util/Lift.lean

39 lines
1.3 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) 2022 Mac Malone. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mac Malone
-/
import Lake.Util.OptionIO
namespace Lake
instance [Pure m] : MonadLiftT Id m where
monadLift act := pure act.run
instance [Alternative m] : MonadLiftT Option m where
monadLift
| some a => pure a
| none => failure
instance [Pure m] [MonadExceptOf ε m] : MonadLiftT (Except ε) m where
monadLift
| .ok a => pure a
| .error e => throw e
instance [Bind m] [MonadReaderOf ρ m] [MonadLiftT n m] : MonadLiftT (ReaderT ρ n) m where
monadLift act := do act (← read)
instance [Monad m] [MonadStateOf σ m] [MonadLiftT n m] : MonadLiftT (StateT σ n) m where
monadLift act := do let (a, s) ← act (← get); set s; pure a
instance [Monad m] [Alternative m] [MonadLiftT n m] : MonadLiftT (OptionT n) m where
monadLift act := act.run >>= liftM
instance [Monad m] [MonadExceptOf ε m] [MonadLiftT n m] : MonadLiftT (ExceptT ε n) m where
monadLift act := act.run >>= liftM
instance [Monad m] [MonadExceptOf ε m] [MonadLiftT BaseIO m] : MonadLiftT (EIO ε) m where
monadLift act := act.toBaseIO >>= liftM
instance [Monad m] [Alternative m] [MonadLiftT BaseIO m] : MonadLiftT OptionIO m where
monadLift act := act.toBaseIO >>= liftM