Skip to content

Commit

Permalink
Nil constructor does not need any argument
Browse files Browse the repository at this point in the history
  • Loading branch information
nathsou committed Apr 5, 2021
1 parent 885e9af commit 36e3ba0
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 17 deletions.
9 changes: 3 additions & 6 deletions examples/lambdaEvaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { DataType, match, VariantOf, genConstructors } from '..';
type Value = DataType<{
Num: { data: number },
Bool: { data: boolean },
Nil: { data: 'nil' },
Nil: {},
Cons: { head: Value, tail: Value },
Closure: { arg: string, body: Expr, env: Env },
RecClosure: { name: string, arg: string, body: Expr, env: Env }
Expand All @@ -31,7 +31,7 @@ type Expr = DataType<{

// generate constructors for all the needed variants

const { Bool, Num, Closure, RecClosure, Cons, ...exprCtors } = genConstructors<Value>()(
const { Bool, Num, Closure, RecClosure, Cons, Nil } = genConstructors<Value>()(
'Bool', 'Num', 'Nil', 'Cons', 'Closure', 'RecClosure'
);

Expand All @@ -42,9 +42,6 @@ const {
'Const', 'MonOp', 'BinOp', 'Var', 'LetIn', 'If', 'Lambda', 'App', 'LetRecIn'
);

// shorthand constructor for Nil
const Nil = () => exprCtors.Nil({ data: 'nil' });

// an environment is a mapping from variable names to values
type Env = { [K in string]: Value };

Expand Down Expand Up @@ -271,7 +268,7 @@ const listPrimes = (upTo: number) => LetRecIn({
}),
inExpr: App({
left: App({ left: Var({ name: 'listPrimes' }), right: Const({ value: Num({ data: upTo }) }) }),
right: Const({ value: Nil() })
right: Const({ value: Nil({}) })
})
});

Expand Down
11 changes: 0 additions & 11 deletions tsconfig.json

This file was deleted.

0 comments on commit 36e3ba0

Please sign in to comment.