Skip to content

Instantly share code, notes, and snippets.

@RaitoBezarius
Created November 18, 2019 23:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RaitoBezarius/879e268a996c16a460ea631b2ea5f5a5 to your computer and use it in GitHub Desktop.
Save RaitoBezarius/879e268a996c16a460ea631b2ea5f5a5 to your computer and use it in GitHub Desktop.
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