Created
June 7, 2014 09:04
-
-
Save fmap/b7188bd08c1bee118384 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 GADTs #-} | |
{-# LANGUAGE DataKinds #-} | |
{-# LANGUAGE KindSignatures #-} | |
{-# LANGUAGE TypeFamilies #-} | |
{-# LANGUAGE RankNTypes #-} | |
data N = Z | S N | |
data Vector :: * -> N -> * where | |
Nil :: Vector a 'Z | |
Cons :: a -> Vector a n -> Vector a ('S n) | |
type family LT (m :: N) (n :: N) :: Bool | |
type instance LT m 'Z = 'False | |
type instance LT 'Z ('S m) = 'True | |
type instance LT ('S m) ('S n) = LT m n | |
data SN :: N -> * where | |
SZ :: SN 'Z | |
SS :: forall (n::N). SN n -> SN ('S n) | |
nth :: (LT m n) ~ 'True => SN m -> Vector a n -> a | |
nth SZ (Cons a _) = a | |
nth (SS s') (Cons _ as) = nth s' as |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment