Skip to content

Instantly share code, notes, and snippets.

@k-bx
Created August 18, 2014 19:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save k-bx/a7b49165399658f87358 to your computer and use it in GitHub Desktop.
Save k-bx/a7b49165399658f87358 to your computer and use it in GitHub Desktop.
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleInstances #-}
import GHC.TypeLits
import Data.Proxy
type family Last (a :: (Nat -> *)) :: Nat
newtype VJ (t :: Nat -> *) (v :: Nat) = VJ Int
data D (v :: Nat)
class Op (t :: Nat -> *) (v :: Nat) where
f :: VJ t v -> VJ t (Last t)
instance Op D 0 where
f (VJ i) = f (VJ i :: VJ D (0+1))
instance Op D 1 where
f (VJ i) = VJ i
main = do
putStrLn "hello"
data Zero
data Succ a
type family Last' (a :: (* -> *)) :: *
data D' v
type instance Last' D' = Succ Zero
newtype VJ' (t :: * -> *) v = VJ' Int
class Op' (t :: * -> *) v where
f' :: VJ' t v -> VJ' t (Last' t)
instance Op' D' Zero where
f' (VJ' i) = f' (VJ' i :: VJ' D' (Succ Zero))
instance Op' D' (Succ Zero) where
f' (VJ' i) = VJ' i
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment