Skip to content

Instantly share code, notes, and snippets.

@gergoerdi
Created August 17, 2012 08:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gergoerdi/3376973 to your computer and use it in GitHub Desktop.
Save gergoerdi/3376973 to your computer and use it in GitHub Desktop.
Untyped lambda-calculus (Haskell)
{-# LANGUAGE GADTs #-}
{-# LANGUAGE DataKinds #-}
data Nat = Z | Suc Nat
data Fin n where
FZ :: Fin (Suc n)
FS :: Fin n -> Fin (Suc n)
inj :: Fin n -> Fin (Suc n)
inj FZ = FZ
inj (FS f) = FS (inj f)
data Exp n where
Var :: Fin n -> Exp n
Lam :: Exp (Suc n) -> Exp n
(:@:) :: Exp n -> Exp n -> Exp n
@gergoerdi
Copy link
Author

Example usage:

_flip :: Exp Z
_flip = Lam $ Lam $ let x = Var (FS FZ)
                        f = Var (inj FZ)
                    in f :@: x

@gergoerdi
Copy link
Author

Actually you don't even need the injection there:

_flip :: Exp Z
_flip = Lam $ Lam $ let x = Var (FS FZ)
                        f = Var FZ
                    in f :@: x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment