Skip to content

Commit

Permalink
More instances
Browse files Browse the repository at this point in the history
  • Loading branch information
augustss committed Sep 25, 2024
1 parent 985c840 commit 3bba110
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/Data/Either.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
module Data.Either(module Data.Either) where
import Prelude() -- do not import Prelude
import Primitives
import Control.Applicative
import Control.Monad
import Data.Bool
import Data.Eq
import Data.Function
Expand Down Expand Up @@ -33,3 +35,13 @@ instance forall a b . (Show a, Show b) => Show (Either a b) where
instance forall a . Functor (Either a) where
fmap _ (Left a) = Left a
fmap f (Right b) = Right (f b)

instance forall a . Applicative (Either a) where
pure b = Right b
Right f <*> Right x = Right (f x)
Right _ <*> Left a = Left a
Left a <*> _ = Left a

instance forall a . Monad (Either a) where
Right b >>= k = k b
Left a >>= _ = Left a

0 comments on commit 3bba110

Please sign in to comment.