Created
November 18, 2019 23:17
-
-
Save RaitoBezarius/879e268a996c16a460ea631b2ea5f5a5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data PosInf a = Infinity | Finite a deriving (Show, Read, Eq) | |
instance Ord a => Ord (PosInf a) where | |
compare Infinity Infinity = EQ | |
compare Infinity Finite{} = GT | |
compare Finite{} Infinity = LT | |
compare (Finite a) (Finite b) = compare a b | |
instance Num a => Num (PosInf a) where | |
Finite x + Finite y = Finite (x + y) | |
_ + _ = Infinity | |
some_constant = 3 | |
give_it_a_try :: (Num a, Eq a) => PosInf a -> PosInf a -> PosInf a | |
give_it_a_try a b | |
| a == Infinity || b == Infinity = Infinity | |
| otherwise = a + b + Finite some_constant |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment