Last active
August 29, 2015 14:20
-
-
Save cocreature/505f978c5ebca9d70db0 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 TypeOperators #-} | |
{-# OPTIONS_GHC -fplugin GHC.TypeLits.Normalise #-} | |
{-# LANGUAGE KindSignatures #-} | |
{-# LANGUAGE GADTs #-} | |
{-# LANGUAGE DataKinds #-} | |
module Fin where | |
import GHC.TypeLits | |
data Vec :: Nat -> * -> * where | |
Nil :: Vec 0 a | |
(:#) :: a -> Vec n a -> Vec (1 + n) a | |
infixr 5 :# | |
data Fin :: Nat -> * where | |
FZ :: Fin k | |
FS :: Fin k -> Fin (1 + k) | |
index :: Vec (1 + n) a -> Fin n -> a | |
index (x:#_) FZ = x | |
index (_:#xs) (FS s) = index xs s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment