Last active
March 19, 2017 20:59
-
-
Save junjihashimoto/b84b280d2bbab2a91d252018c28f24a1 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
{-# LANGUAGE DataKinds #-} | |
{-# LANGUAGE TypeFamilies #-} | |
{-# LANGUAGE TypeOperators #-} | |
{-# LANGUAGE UndecidableInstances #-} | |
import GHC.TypeLits | |
data V (n::Nat) = V | |
deriving Show | |
type family Add (x :: Nat) (y :: Nat) :: Nat where | |
Add x y = x+y | |
add :: (KnownNat n, KnownNat m) => V n -> V m -> V (Add n m) | |
add _ _ = V | |
eq' :: (KnownNat n) => V n -> V n -> V n | |
eq' a _ = a | |
main = do | |
let v1 = V :: V 1 | |
v2 = V :: V 2 | |
v3 = V :: V 3 | |
print $ natVal $ add v1 v2 | |
print $ natVal $ eq' (add v1 v2) v3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment