Skip to content

Instantly share code, notes, and snippets.

@esoeylemez
Last active October 17, 2016 09:00
Show Gist options
  • Save esoeylemez/010011b6b78dc1b9d7dcdec9d4249212 to your computer and use it in GitHub Desktop.
Save esoeylemez/010011b6b78dc1b9d7dcdec9d4249212 to your computer and use it in GitHub Desktop.
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE RankNTypes #-}
data Number
= DoubleNum !Double
| IntegerNum !Integer
| IntNum !Int
| RationalNum !Rational
withNumber :: (c Double, c Int, c Integer, c Rational) => (forall a. (c a) => a -> r) -> Number -> r
withNumber f (DoubleNum x) = f x
withNumber f (IntegerNum x) = f x
withNumber f (IntNum x) = f x
withNumber f (RationalNum x) = f x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment