-
-
Save Tarmean/f47d880663e35e8c82165bc443bfb202 to your computer and use it in GitHub Desktop.
This file contains 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 Number = forall a . Number (TypeEnum a) a | |
higherPred :: forall dict . (forall a . TypeEnum a -> dict) -> Number -> Number -> dict | |
higherPred f (Number e1 _) (Number e2 _) = if ordering e1 >= ordering e2 then f e1 else f e2 | |
data NumDict = forall a . Num a => NumDict (TypeEnum a) | |
matchNum :: forall a . TypeEnum a -> NumDict | |
matchNum Integer = NumDict Integer | |
matchNum Rational = NumDict Rational | |
matchNum Real = NumDict Real | |
matchNum Complex = NumDict Complex | |
liftNum :: (forall a. Num a => a -> a -> a) -> Number -> Number -> Number | |
liftNum f a b = case higherPred matchNum a b of | |
NumDict d -> Number d $ to d a `f` to d b |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment