Skip to content

Instantly share code, notes, and snippets.

@TerrorJack
Created October 10, 2018 04:20
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 TerrorJack/713cd77946487d81641793e26de196a7 to your computer and use it in GitHub Desktop.
Save TerrorJack/713cd77946487d81641793e26de196a7 to your computer and use it in GitHub Desktop.
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE RankNTypes #-}
module DeBruijn
( Expr(..)
, DBI(..)
, toDBI
) where
import Control.Applicative
class Expr t where
lam :: (t -> t) -> t
app :: t -> t -> t
data DBI
= Var Int
| Lam DBI
| App DBI
DBI
deriving (Eq, Show)
instance Expr (Int -> DBI) where
lam f i = Lam (f (\j -> Var (j - i - 1)) (i + 1))
app = liftA2 App
toDBI ::
(forall t. Expr t =>
t)
-> DBI
toDBI = ($ (0 :: Int))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment