32 lines
1.1 KiB
JavaScript
32 lines
1.1 KiB
JavaScript
import { fnType, getListType } from "../type_registry.js";
|
|
import {Type, Function} from "../metacircular.js";
|
|
import {Int} from "../primitives/symbols.js";
|
|
|
|
export const makeListModule = elementType => {
|
|
// List<elementType> type depends on elementType
|
|
// generating it another time, will give the same type (structurally equivalent):
|
|
const ListOfElement = getListType(elementType);
|
|
|
|
const emptyList = {l:[]};
|
|
|
|
const get = ls => i => ls.l[i];
|
|
const getBoundType = fnType({in: Int, out: elementType});
|
|
const getType = fnType({in: ListOfElement, out: getBoundType});
|
|
|
|
const push = ls => elem => ({l:ls.l.concat([elem])});
|
|
const pushBoundType = fnType({in: elementType, out: ListOfElement});
|
|
const pushType = fnType({in: ListOfElement, out: pushBoundType});
|
|
|
|
return [
|
|
{i: ListOfElement, t: Type},
|
|
{i: emptyList , t: ListOfElement},
|
|
|
|
{i: get , t: getType},
|
|
{i: getType , t: Function},
|
|
{i: getBoundType , t: Function},
|
|
|
|
{i: push , t: pushType},
|
|
{i: pushType , t: Function},
|
|
{i: pushBoundType, t: Function},
|
|
];
|
|
};
|