progress
This commit is contained in:
parent
3596e01c28
commit
6af72e525c
3 changed files with 31 additions and 5 deletions
|
|
@ -36,5 +36,9 @@ const weirdFnType = makeGeneric(a =>
|
|||
in: fnType({in: a, out: Int}),
|
||||
out: fnType({in: lsType(a), out: a}),
|
||||
}));
|
||||
// we call this function with parameter of type (b -> b) ...
|
||||
// giving these substitutions:
|
||||
// a := b
|
||||
// b := Int
|
||||
console.log("should be: [Int] -> Int");
|
||||
console.log(pretty(assign(weirdFnType, idFnType)));
|
||||
console.log(pretty(assign(weirdFnType, idFnType)));
|
||||
|
|
|
|||
14
main.js
14
main.js
|
|
@ -7,6 +7,7 @@ import { Type } from './type.js';
|
|||
|
||||
class Context {
|
||||
constructor(mod) {
|
||||
this.mod = mod;
|
||||
this.types = new DefaultMap(() => new Set()); // instance to type
|
||||
this.instances = new DefaultMap(() => new Set()); // type to instance
|
||||
|
||||
|
|
@ -26,11 +27,18 @@ class Context {
|
|||
this.functionsTo .getdefault(t.params[1], true).add(fn);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
addToCtx({i, t}) {
|
||||
return new Context({l:[
|
||||
...this.mod.l,
|
||||
{i, t},
|
||||
]})
|
||||
}
|
||||
}
|
||||
|
||||
const ctx = new Context({l:[
|
||||
let ctx = new Context({l:[
|
||||
...ModuleStd.l,
|
||||
...ModulePoint.l,
|
||||
]});
|
||||
|
|
@ -257,6 +265,8 @@ async function transform(i, t) {
|
|||
async function apply(i, fn, fnT) {
|
||||
const result = fn(i);
|
||||
const resultType = fnT.params[1];
|
||||
// update context with newly produced value
|
||||
ctx = ctx.addToCtx({i: result, t: resultType});
|
||||
const {strI: strResult, strT: strResultType} = prettyIT({i: result, t: resultType});
|
||||
console.log(`result = ${strResult} :: ${strResultType}`);
|
||||
return instanceOrTypeOrFnOptions({i: result, t: resultType});
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { typedFnType } from "./types.js";
|
||||
import { fnType, typedFnType } from "./types.js";
|
||||
import { Type } from "../type.js";
|
||||
import { Int } from "../primitives/types.js";
|
||||
import { makeGeneric } from "../generics/generics.js";
|
||||
|
|
@ -8,7 +8,7 @@ import { lsType } from "./types.js";
|
|||
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])});
|
||||
const push = ls => elem => ({l:ls.l.concat([elem])});
|
||||
|
||||
export const ModuleList = {l:[
|
||||
// Type -> Type
|
||||
|
|
@ -43,4 +43,16 @@ export const ModuleList = {l:[
|
|||
/* out */ (lsType(a))
|
||||
)
|
||||
))),
|
||||
|
||||
// [a] -> a -> [a]
|
||||
...typedFnType(push, fnType =>
|
||||
makeGeneric(a =>
|
||||
fnType
|
||||
(lsType(a))
|
||||
(fnType
|
||||
(a)
|
||||
(lsType(a))
|
||||
)
|
||||
)
|
||||
),
|
||||
]};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue