shithub: MicroHs

Download patch

ref: 3bba110c22dda29ab454a33656daabb4f3d95c7b
parent: 985c8409a395739122e926ec058fee80aa55532a
author: Lennart Augustsson <lennart@augustsson.net>
date: Wed Sep 25 07:11:08 EDT 2024

More instances

--- a/lib/Data/Either.hs
+++ b/lib/Data/Either.hs
@@ -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
@@ -33,3 +35,13 @@
 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