~/bend-docscommunity

maybe.bend checks

raw source on the hub · import bend-mathlib@0.4.0.0/maybe.bend as MMaybe

bend-mathlib/maybe.bend: Maybe monad and map laws over &2.

1 import
import Base

Laws

law maybe_pure_bind provedsource · line 5 · raw

@-A:Data -> @-B:Data -> @-f:(@_:A -> Maybe<&2, B>) -> @-x:A -> {Maybe.bind(&2, A, B, Maybe.pure(&2, A, x), f) == f(x) : Maybe<&2, B>}

Left identity: binding a pure value applies the function.

law maybe_bind_pure provedsource · line 16 · raw

@-A:Data -> @m:Maybe<&2, A> -> {Maybe.bind(&2, A, A, m, x => Maybe.pure(&2, A, x)) == m : Maybe<&2, A>}

Right identity: binding pure is the identity.

law maybe_bind_assoc provedsource · line 29 · raw

@-A:Data -> @-B:Data -> @-C:Data -> @-f:(@_:A -> Maybe<&2, B>) -> @-g:(@_:B -> Maybe<&2, C>) -> @m:Maybe<&2, A> -> {Maybe.bind(&2, B, C, Maybe.bind(&2, A, B, m, f), g) == Maybe.bind(&2, A, C, m, x => Maybe.bind(&2, B, C, f(x), g)) : Maybe<&2, C>}

Bind is associative.

law maybe_map_pure provedsource · line 46 · raw

@-A:Data -> @-B:Data -> @-f:(@_:A -> B) -> @-x:A -> {Maybe.map(&2, A, B, f, Maybe.pure(&2, A, x)) == Maybe.pure(&2, B, f(x)) : Maybe<&2, B>}

Mapping a pure value is pure of the mapped value.

law maybe_map_compose provedsource · line 57 · raw

@-A:Data -> @-B:Data -> @-C:Data -> @-f:(@_:A -> B) -> @-g:(@_:B -> C) -> @m:Maybe<&2, A> -> {Maybe.map(&2, B, C, g, Maybe.map(&2, A, B, f, m)) == Maybe.map(&2, A, C, x => g(f(x)), m) : Maybe<&2, C>}

Mapping a composition maps the composition.

law maybe_pure_bind_sym provedsource · line 76 · raw

@-A:Data -> @-B:Data -> @-f:(@_:A -> Maybe<&2, B>) -> @-x:A -> {f(x) == Maybe.bind(&2, A, B, Maybe.pure(&2, A, x), f) : Maybe<&2, B>}

Left identity: binding a pure value applies the function, reversed to rewrite toward the simple side.

law maybe_bind_pure_sym provedsource · line 87 · raw

@-A:Data -> @m:Maybe<&2, A> -> {m == Maybe.bind(&2, A, A, m, x => Maybe.pure(&2, A, x)) : Maybe<&2, A>}

Right identity: binding pure is the identity, reversed to rewrite toward the simple side.

law maybe_bind_assoc_sym provedsource · line 96 · raw

@-A:Data -> @-B:Data -> @-C:Data -> @-f:(@_:A -> Maybe<&2, B>) -> @-g:(@_:B -> Maybe<&2, C>) -> @m:Maybe<&2, A> -> {Maybe.bind(&2, A, C, m, x => Maybe.bind(&2, B, C, f(x), g)) == Maybe.bind(&2, B, C, Maybe.bind(&2, A, B, m, f), g) : Maybe<&2, C>}

Bind is associative, reversed to rewrite toward the simple side.

law maybe_map_pure_sym provedsource · line 109 · raw

@-A:Data -> @-B:Data -> @-f:(@_:A -> B) -> @-x:A -> {Maybe.pure(&2, B, f(x)) == Maybe.map(&2, A, B, f, Maybe.pure(&2, A, x)) : Maybe<&2, B>}

Mapping a pure value is pure of the mapped value, reversed to rewrite toward the simple side.

law maybe_map_compose_sym provedsource · line 120 · raw

@-A:Data -> @-B:Data -> @-C:Data -> @-f:(@_:A -> B) -> @-g:(@_:B -> C) -> @m:Maybe<&2, A> -> {Maybe.map(&2, A, C, x => g(f(x)), m) == Maybe.map(&2, B, C, g, Maybe.map(&2, A, B, f, m)) : Maybe<&2, C>}

Mapping a composition maps the composition, reversed to rewrite toward the simple side.