Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
data PosInf a = Infinity | Num a deriving (Show, Read, Eq)
instance Ord a => Ord (PosInf a) where
compare Infinity Infinity = EQ
compare Infinity Num{} = GT
compare Num{} Infinity = LT
compare (Num a) (Num b) = compare a b
pInfty :: PosInf a
pInfty = Infinity
give_it_a_try :: PosInf a => a -> a
give_it_a_try a b
| a == Infinity || b == Infinity -> Infinity
| otherwise = a + b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment