Created
May 14, 2019 02:58
-
-
Save YuMingLiao/d199732449b6f60472396f115c601f84 to your computer and use it in GitHub Desktop.
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 #-} | |
{-# LANGUAGE TypeOperators #-} | |
{-# LANGUAGE DataKinds #-} | |
{-# LANGUAGE UndecidableInstances #-} | |
data Nat = Z | S Nat | |
data Expr = Num Nat | |
| Add Expr Expr | |
type family Eval (expr :: Expr) :: Nat where | |
Eval ('Num n) = n | |
Eval ('Add e e) = Add (Eval e) (Eval e) | |
type family Add (x :: Nat) (y :: Nat) :: Nat where | |
Add 'Z y = y | |
Add ('S x) y = 'S (Add x y) | |
-- *Main> :kind! Eval ('Add ('Num ('S 'Z)) ('Num ('Z))) | |
-- Eval ('Add ('Num ('S 'Z)) ('Num ('Z))) :: Nat | |
-- = Eval ('Add ('Num ('S 'Z)) ('Num 'Z)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment