Created
May 18, 2014 20:20
-
-
Save wavewave/eda833a764652d6ddc1a to your computer and use it in GitHub Desktop.
Haskell type-level literal test (ghc 7.8.2)
This file contains hidden or 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
| {-# LANGUAGE DataKinds #-} | |
| {-# LANGUAGE KindSignatures #-} | |
| {-# LANGUAGE TypeOperators #-} | |
| {-# LANGUAGE GADTs #-} | |
| {-# LANGUAGE ExplicitForAll #-} | |
| import GHC.TypeLits | |
| data Proxy (a :: Nat) = Proxy | |
| data TLT | |
| data TEQ | |
| data TGT | |
| data Compare (a :: Nat) (b :: Nat) r where | |
| LessThan :: forall (a :: Nat) (b :: Nat) (x :: Nat). (a+x) ~ b => Proxy a -> Proxy b -> Compare a b TLT | |
| Equal :: forall (a :: Nat) (b :: Nat). a ~ (b + 0) => Proxy a -> Proxy b -> Compare a b TEQ | |
| GreaterThan :: forall (a :: Nat) (b :: Nat) (x :: Nat). a ~ (b+x) => Proxy a -> Proxy b -> Compare a b TGT | |
| test :: Compare a b r -> String | |
| test (LessThan _ _) = "LessThan" | |
| test (Equal _ _) = "Equal" | |
| test (GreaterThan _ _) = "GreaterThan" | |
| main = do | |
| print "hello" | |
| print (test (LessThan (Proxy :: Proxy 1) (Proxy :: Proxy 3))) | |
| print (test (Equal (Proxy :: Proxy 1) (Proxy :: Proxy 1))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment