Skip to content

Instantly share code, notes, and snippets.

@leshow
Created February 5, 2018 18:01
Show Gist options
  • Select an option

  • Save leshow/90653a7cd143bcc5164317818c874ef2 to your computer and use it in GitHub Desktop.

Select an option

Save leshow/90653a7cd143bcc5164317818c874ef2 to your computer and use it in GitHub Desktop.
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
import Data.Monoid ((<>))
data Nat = Zero | Succ Nat
data List (n :: Nat) (a :: *) where
Nil :: List 'Zero a
Cons :: a -> List n a -> List ('Succ n) a
instance Show a => Show (List n a) where
show Nil = "Nil"
show (Cons a as) = "Cons" <> show a <> " (" <> show as <> ") "
-- add
type family Add (n :: Nat) (m :: Nat) where
Add 'Zero m = m
Add ('Succ n) m = 'Succ (Add n m)
append :: List n a -> List m a -> List (Add n m) 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