Skip to content

Instantly share code, notes, and snippets.

@Tarmean
Last active February 2, 2017 23:26
Show Gist options
  • Save Tarmean/f47d880663e35e8c82165bc443bfb202 to your computer and use it in GitHub Desktop.
Save Tarmean/f47d880663e35e8c82165bc443bfb202 to your computer and use it in GitHub Desktop.
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