wip
This commit is contained in:
parent
afd78c3b3e
commit
29d20b2273
25 changed files with 369 additions and 469 deletions
|
|
@ -1,16 +1,51 @@
|
|||
import { lsType } from "./list_common.js";
|
||||
import { fnType } from "../metacircular.js";
|
||||
import {Type, Function} from "../metacircular.js";
|
||||
import { makeListModule } from "./list_common.js";
|
||||
import { Module } from "./list_types/module.js";
|
||||
import { typedFnType } from "./function.js";
|
||||
import { Type } from "../metacircular.js";
|
||||
import { Int } from "../primitives/symbols.js";
|
||||
import { DefaultMap } from "../util.js";
|
||||
import { makeGeneric } from "../generics/generics.js";
|
||||
|
||||
const Type_to_Type = fnType({in: Type, out: Type});
|
||||
const Type_to_Module = fnType({in: Type, out: Module});
|
||||
const symbolList = Symbol('List');
|
||||
|
||||
const listTypeRegistry = new DefaultMap(elementType => ({
|
||||
symbol: symbolList,
|
||||
params: [elementType],
|
||||
}));
|
||||
|
||||
// type constructor
|
||||
export const lsType = elementType => listTypeRegistry.getdefault(elementType, true);
|
||||
|
||||
// 'normal' implementation
|
||||
const emptyList = {l:[]};
|
||||
const get = ls => i => ls.l[i];
|
||||
const put = ls => i => elem => ({l: ls.l.with(Number(i), elem)});
|
||||
// const push = ls => elem => ({l:ls.l.concat([elem])});
|
||||
|
||||
export const ModuleList = {l:[
|
||||
{i: lsType , t: Type_to_Type},
|
||||
{i: Type_to_Type , t: Function},
|
||||
// Type -> Type
|
||||
...typedFnType(lsType, fnType => fnType
|
||||
/* in */ (Type)
|
||||
/* out */ (Type)
|
||||
),
|
||||
|
||||
{i: makeListModule, t: Type_to_Module},
|
||||
{i: Type_to_Module, t: Function},
|
||||
// [a]
|
||||
{i: emptyList, t: makeGeneric(a => lsType(a))},
|
||||
|
||||
// [a] -> Int -> a
|
||||
...typedFnType(get, fnType => makeGeneric(a => fnType
|
||||
/* in */ (lsType(a))
|
||||
/* out */ (fnType
|
||||
/* in */ (Int)
|
||||
/* out */ (a)
|
||||
))),
|
||||
|
||||
// [a] -> Int -> a -> [a]
|
||||
...typedFnType(put, fnType => makeGeneric(a => fnType
|
||||
/* in */ (lsType(a))
|
||||
/* out */ (fnType
|
||||
/* in */ (Int)
|
||||
/* out */ (fnType
|
||||
/* in */ (a)
|
||||
/* out */ (lsType(a))
|
||||
)
|
||||
))),
|
||||
]};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue