Commit 0ccc52fd authored by Steffen Michels's avatar Steffen Michels

add == & < instance for Data.Either

parent 9df117b2
Pipeline #19695 failed with stage
in 3 minutes and 8 seconds
......@@ -5,6 +5,7 @@ definition module Data.Either
* used inside generic functions, since most generic functions treat this
* type in a special way which may lead to strange behavior.
*/
from StdOverloaded import class <
from Control.Applicative import class pure, class <*>, class Applicative, class *>, class <*, class Alternative
from Control.Monad import class Monad
from Data.Functor import class Functor
......@@ -16,6 +17,8 @@ from Data.GenEq import generic gEq
:: Either a b = Left a | Right b
instance == (Either a b) | == a & == b
instance < (Either a b) | < a & < b
instance Functor (Either a)
instance pure (Either e)
instance <*> (Either e)
......
implementation module Data.Either
from StdEnv import flip, id, o, const
from StdEnv import flip, id, o, const, class < (..)
from StdMisc import abort
import Control.Applicative
import Data.Monoid
......@@ -12,6 +12,17 @@ from Data.Traversable import class Traversable(..)
import Data.Bifunctor
import Data.GenEq
instance == (Either a b) | == a & == b where
== (Left x) (Left y) = x == y
== (Right x) (Right y) = x == y
== _ _ = False
instance < (Either a b) | < a & < b where
< (Left x) (Left y) = x < y
< (Right x) (Right y) = x < y
< (Left _) (Right _) = True
< (Right _) (Left _) = False
instance Functor (Either a) where
fmap f (Left l) = Left l
fmap f (Right r) = Right (f r)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment