Skip to content

Instantly share code, notes, and snippets.

@bond15
Created March 19, 2021 22:37
Show Gist options
  • Save bond15/af715119dc2509050c4d259b74f67007 to your computer and use it in GitHub Desktop.
Save bond15/af715119dc2509050c4d259b74f67007 to your computer and use it in GitHub Desktop.
Haskell Type Level Nats
{-# LANGUAGE GADTs #-}
module Mat where
--import GHC.TypeLits
data Z = Z
data S a = S a
type Zero = Z
type One = S Zero
type Two = S One
type Three = S Two
type Four = S Three
data List s a where
Nil :: List Z a
Cons :: a -> List s a -> List (S s) a
ex :: List Four Char
ex = Cons 'a' $ Cons 'b' $ Cons 'c' $ Cons 'd' Nil
append :: List n a -> List m a -> List (m + n) --
append = undefined
-- s row, s' col
data Mat s s' a where
Empty :: Mat Z Z a
R :: List s (List s' a) -> Mat s s' a
r1 = Cons 1 $ Cons 2 $ Cons 3 Nil
r2 = Cons 4 $ Cons 5 $ Cons 6 Nil
mat :: Mat Two Three Int
mat = R $ Cons r1 $ Cons r2 Nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment