Skip to content

Instantly share code, notes, and snippets.

@mietek
Created November 12, 2016 17:06
Show Gist options
  • Save mietek/354412e479af35356913d08178d4c72e to your computer and use it in GitHub Desktop.
Save mietek/354412e479af35356913d08178d4c72e to your computer and use it in GitHub Desktop.
{-# LANGUAGE ScopedTypeVariables #-}
data Zero
data Suc n
type One = Suc Zero
type Two = Suc One
type Three = Suc Two
class Nat n where
fromNat :: Num a => n -> a
instance Nat Zero where
fromNat _ = 0
instance Nat n => Nat (Suc n) where
fromNat _ = fromNat (undefined :: n) + 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment