Last active
August 29, 2015 14:04
-
-
Save fmap/ece133d4452b10add990 to your computer and use it in GitHub Desktop.
Construct vectors of length LEQ some bound.
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 Rank2Types #-} | |
-- Construct vectors of length LEQ some bound. :-) | |
data Natural where | |
Zero :: Natural | |
Succ :: Natural -> Natural | |
data SNatural :: Natural -> * where | |
SZero :: SNatural 'Zero | |
SSucc :: forall (n :: Natural). SNatural n -> SNatural ('Succ n) | |
data Vector :: * -> Natural -> Natural -> * where | |
VNil :: SNatural n -> Vector _type n n | |
VCons :: _type -> Vector _type n ('Succ m) -> Vector _type n m | |
x :: Vector Char (Succ (Succ Zero)) (Succ (Succ Zero)) | |
x = VNil (SSucc (SSucc SZero)) | |
y :: Vector Char (Succ (Succ Zero)) (Succ Zero) | |
y = VCons 'a' $ VNil (SSucc (SSucc SZero)) | |
z = VCons 'c' . VCons 'b' . VCons 'a' $ VNil (SSucc (SSucc SZero)) -- Doesn't typecheck! :D |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment