Skip to content

Commit

Permalink
Merge pull request puffnfresh#149 from stew/master
Browse files Browse the repository at this point in the history
add left/right monads for Either
  • Loading branch information
puffnfresh committed Oct 2, 2012
2 parents d6788a5 + e3be7c8 commit a70f225
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/prelude.roy
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,22 @@ let optionMonad = {
// 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
Expand Down

0 comments on commit a70f225

Please sign in to comment.