Skip to content

Instantly share code, notes, and snippets.

@junjihashimoto
Last active March 19, 2017 20:59
Show Gist options
  • Save junjihashimoto/b84b280d2bbab2a91d252018c28f24a1 to your computer and use it in GitHub Desktop.
Save junjihashimoto/b84b280d2bbab2a91d252018c28f24a1 to your computer and use it in GitHub Desktop.
{-# 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