interactive prompt can handle polymorphic types
This commit is contained in:
parent
a0e3aa0cb3
commit
4a4983f693
20 changed files with 485 additions and 276 deletions
|
|
@ -1,16 +1,19 @@
|
|||
import { typedFnType } from "./types.js";
|
||||
import { Char, Type } from "../primitives/types.js";
|
||||
import { Char, GenericType, Type } from "../primitives/types.js";
|
||||
import { Int } from "../primitives/types.js";
|
||||
import { makeGeneric } from "../generics/generics.js";
|
||||
import { lsType } from "./types.js";
|
||||
import { Typed } from "../typed.js"
|
||||
|
||||
// 'normal' implementation
|
||||
const emptyList = {l:[]};
|
||||
const emptyListType = makeGeneric(a => lsType(a));
|
||||
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 String = lsType(Char); // alias
|
||||
export const Module = lsType(Typed);
|
||||
|
||||
export const ModuleList = {l:[
|
||||
// Type -> Type
|
||||
|
|
@ -21,7 +24,8 @@ export const ModuleList = {l:[
|
|||
),
|
||||
|
||||
// [a]
|
||||
{i: emptyList, t: makeGeneric(a => lsType(a))},
|
||||
{i: emptyList, t: emptyListType},
|
||||
{i: emptyListType, t: GenericType},
|
||||
|
||||
// [a] -> Int -> a
|
||||
...typedFnType(get, fnType =>
|
||||
|
|
@ -31,7 +35,7 @@ export const ModuleList = {l:[
|
|||
/* out */ (fnType
|
||||
/* in */ (Int)
|
||||
/* out */ (a)
|
||||
))),
|
||||
)), GenericType),
|
||||
|
||||
// [a] -> Int -> a -> [a]
|
||||
...typedFnType(put, fnType =>
|
||||
|
|
@ -44,7 +48,7 @@ export const ModuleList = {l:[
|
|||
/* in */ (a)
|
||||
/* out */ (lsType(a))
|
||||
)
|
||||
))),
|
||||
)), GenericType),
|
||||
|
||||
// [a] -> a -> [a]
|
||||
...typedFnType(push, fnType =>
|
||||
|
|
@ -55,8 +59,5 @@ export const ModuleList = {l:[
|
|||
(a)
|
||||
(lsType(a))
|
||||
)
|
||||
)
|
||||
),
|
||||
|
||||
// {i: String, t: Type}, // alias
|
||||
), GenericType),
|
||||
]};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue