Created
May 30, 2019 13:45
-
-
Save BoeingX/32f73ef6fb00654da653f6c1e20ff166 to your computer and use it in GitHub Desktop.
Peano numbers
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 GADTs #-} | |
| {-# LANGUAGE TypeFamilies #-} | |
| {-# LANGUAGE FlexibleInstances #-} | |
| data Z | |
| data S n | |
| data Natural :: * -> * where | |
| NumZ :: Natural Z | |
| NumS :: Natural n -> Natural (S n) | |
| toInt :: Natural n -> Int | |
| toInt NumZ = 0 | |
| toInt (NumS n) = 1 + toInt n |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment