Skip to content

Instantly share code, notes, and snippets.

@cocreature
Last active August 29, 2015 14:20
Show Gist options
  • Save cocreature/505f978c5ebca9d70db0 to your computer and use it in GitHub Desktop.
Save cocreature/505f978c5ebca9d70db0 to your computer and use it in GitHub Desktop.
{-# 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