Created
February 5, 2018 18:01
-
-
Save leshow/90653a7cd143bcc5164317818c874ef2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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