lean4-htt/library/init/control/monad.lean
Leonardo de Moura a3a8165388 feat(library/init/control/monad): provide seq_right default implementation for monad
It was using the `seq_right` from `applicative` which is
```
(seq_right := λ α β a b, const α id <$> a <*> b)
```
and horrible code was being generated.

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2018-09-20 08:39:25 -07:00

23 lines
724 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) Luke Nelson and Jared Roesch. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura, Luke Nelson, Jared Roesch, Sebastian Ullrich
-/
prelude
import init.control.applicative
universes u v
open function
class has_bind (m : Type u → Type v) :=
(bind : Π {α β : Type u}, m α → (α → m β) → m β)
export has_bind (bind)
infixl ` >>= `:55 := bind
class monad (m : Type u → Type v) extends applicative m, has_bind m : Type (max (u+1) v) :=
(map := λ α β f x, x >>= pure ∘ f)
(seq := λ α β f x, f >>= (<$> x))
(seq_left := λ α β x y, x >>= λ a, y >>= λ _, pure a)
(seq_right := λ α β x y, x >>= λ _, y)