Commits

Brian McKenna committed a70f225 Merge

Merge pull request #149 from stew/master

add left/right monads for Either

  • Participants
  • Parent commits d6788a5, e3be7c8

Comments (0)

Files changed (1)

File lib/prelude.roy

 // Either type.
 data Either a b = Left a | Right b
 
+let rightMonad = {
+  return: λx → Right x
+
+  bind: λx f → match x
+    case (Left a) = Left a
+    case (Right a) = f a
+}
+
+let leftMonad = {
+  return: λx → Left x
+
+  bind: λx f → match x 
+    case (Left a) = f a
+    case (Right a) = Right a
+}
+
 // Math constants.
 let π: Number = Math.PI
 let π2 = π * 2