No matching definitions.

tur/typeclass-bifunctor

stdlib/typeclass-bifunctor.tur

minimal Bifunctor typeclass stub.

Auto-loaded (and loadable directly) so a module can declare (definstance Bifunctor [...] ...) without importing the full typeclass.tur. The full typeclass.tur (with every typeclass) remains available on demand via (load "stdlib/typeclass.tur"); defclass redefinition is idempotent, so the two coexist.

Since: stdlib-hkt-consolidation T1

defclass

Bifunctor

(defclass Bifunctor [^^f])

map over both type arguments of a two-parameter type at once.

^^fthe type constructor (kind * -> * -> *), e.g. Result
(bimap [container :(f a b) fn-left :(fn [a] c) fn-right :(fn [b] d)] :(f c d))

container with fn-left applied on one side and fn-right on the other. Which side is "left" is the instance's: Result's follows Haskell's Either, so fn-left maps an err and fn-right an ok.

(bimap c (fn [x] x) (fn [y] y))   = c
(ok-val (bimap (:: (ok 20) (Result int int)) (fn [e : int] : int (- 0 e)) (fn [x : int] : int (+ x 1))))   ; => 21
(err-val (bimap (:: (err 5) (Result int int)) (fn [e : int] : int (- 0 e)) (fn [x : int] : int (+ x 1))))  ; => -5

Result

Since: Phase HKT H5