Skip to content

Instantly share code, notes, and snippets.

@BoeingX
Created May 30, 2019 13:45
Show Gist options
  • Select an option

  • Save BoeingX/32f73ef6fb00654da653f6c1e20ff166 to your computer and use it in GitHub Desktop.

Select an option

Save BoeingX/32f73ef6fb00654da653f6c1e20ff166 to your computer and use it in GitHub Desktop.
Peano numbers
{-# 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