glambda-1.0.2: A simply typed lambda calculus interpreter, written with GADTs

Copyright(C) 2015 Richard Eisenberg
LicenseBSD-style (see LICENSE)
MaintainerRichard Eisenberg (rae@cs.brynmawr.edu)
Stabilityexperimental
Safe HaskellSafe
LanguageHaskell2010

Language.Glambda.Exp

Description

The Exp GADT. Glambda expressions encoded in an Exp value are *always* well-typed.

Synopsis

Documentation

data Exp :: [*] -> * -> * where Source #

Exp ctx ty is a well-typed expression of type ty in context ctx. Note that a context is a list of types, where a type's index in the list indicates the de Bruijn index of the associated term-level variable.

Constructors

Var :: Elem ctx ty -> Exp ctx ty 
Lam :: Exp (arg ': ctx) res -> Exp ctx (arg -> res) 
App :: Exp ctx (arg -> res) -> Exp ctx arg -> Exp ctx res 
Arith :: Exp ctx Int -> ArithOp ty -> Exp ctx Int -> Exp ctx ty 
Cond :: Exp ctx Bool -> Exp ctx ty -> Exp ctx ty -> Exp ctx ty 
Fix :: Exp ctx (ty -> ty) -> Exp ctx ty 
IntE :: Int -> Exp ctx Int 
BoolE :: Bool -> Exp ctx Bool 

Instances

Pretty (Exp ctx ty) Source # 

Methods

pretty :: Exp ctx ty -> Doc #

prettyList :: [Exp ctx ty] -> Doc #

PrettyExp (Exp ctx ty) Source # 

Methods

prettyExp :: Coloring -> Prec -> Exp ctx ty -> Doc Source #

data Elem :: [a] -> a -> * where Source #

Elem xs x is evidence that x is in the list xs. EZ :: Elem xs x is evidence that x is the first element of xs. ES ev :: Elem xs x is evidence that x is one position later in xs than is indicated in ev

Constructors

EZ :: Elem (x ': xs) x 
ES :: Elem xs x -> Elem (y ': xs) x 

class GlamVal t where Source #

Classifies types that can be values of glambda expressions

Minimal complete definition

val

Associated Types

data Val t Source #

Well-typed closed values. Encoded as a data family with newtype instances in order to avoid runtime checking of values

Methods

val :: Val t -> Exp '[] t Source #

Convert a glambda value back into a glambda expression

Instances

GlamVal Bool Source # 

Associated Types

data Val Bool :: * Source #

Methods

val :: Val Bool -> Exp [*] Bool Source #

GlamVal Int Source # 

Associated Types

data Val Int :: * Source #

Methods

val :: Val Int -> Exp [*] Int Source #

GlamVal (a -> b) Source # 

Associated Types

data Val (a -> b) :: * Source #

Methods

val :: Val (a -> b) -> Exp [*] (a -> b) Source #

prettyVal :: Val t -> STy t -> Doc Source #

Pretty-prints a Val. This needs type information to know how to print. Pattern matching gives GHC enough information to be able to find the GlamVal instance needed to construct the PrettyExp instance.

eqExp :: Exp ctx1 ty1 -> Exp ctx2 ty2 -> Bool Source #

Equality on expressions, needed for testing