Created
March 3, 2019 18:39
-
-
Save chowells79/13a3349f94dcdac1d8648762b0935643 to your computer and use it in GitHub Desktop.
Simplest useful type-level programming
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 TypeFamilies, GADTs #-} | |
{-# LANGUAGE StandaloneDeriving, EmptyDataDecls #-} | |
data Z | |
data S n | |
data Vec n a where | |
Nil :: Vec Z a | |
Cons :: a -> Vec n a -> Vec (S n) a | |
deriving instance Show a => Show (Vec n a) | |
deriving instance Eq a => Eq (Vec n a) | |
deriving instance Ord a => Ord (Vec n a) | |
type family Plus m n :: * where | |
Plus Z n = n | |
Plus (S m) n = S (Plus m n) | |
append :: Vec m a -> Vec n a -> Vec (Plus m n) a | |
append Nil ys = ys | |
append (Cons x xs) ys = Cons x (append xs ys) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment