add example: defining a higher-order function (doesn't work yet)

This commit is contained in:
Joeri Exelmans 2025-05-19 15:55:04 +02:00
parent ec2944cdb7
commit f9c28ac8c8
2 changed files with 9 additions and 6 deletions

View file

@ -3,7 +3,7 @@ import './App.css';
import { GlobalContext } from './GlobalContext';
import { ExprBlock, type ExprBlockState } from './ExprBlock';
import { extendedEnv } from './EnvContext';
import { biggerExample, initialEditorState, lambda2Params, nonEmptyEditorState, tripleFunctionCallEditorState } from "./configurations";
import { biggerExample, higherOrder, initialEditorState, lambda2Params, nonEmptyEditorState, tripleFunctionCallEditorState } from "./configurations";
import { evalEditorBlock } from "./eval";
const commands: [string, string[], string][] = [
@ -15,11 +15,12 @@ const commands: [string, string[], string][] = [
];
const examples: [string, ExprBlockState][] = [
["empty editor", initialEditorState],
["push to list", nonEmptyEditorState],
["empty editor" , initialEditorState ],
["push to list" , nonEmptyEditorState ],
["function w/ 4 params", tripleFunctionCallEditorState],
["bigger example", biggerExample],
["lambda 2 params", lambda2Params],
["bigger example" , biggerExample ],
["lambda 2 params" , lambda2Params ],
["higher order" , higherOrder ],
];
type AppState = {

View file

@ -126,4 +126,6 @@ export const lambda2Params: ExprBlockState = {
}
}
}
};
};
export const higherOrder: ExprBlockState = {"kind":"let","inner":{"kind":"call","fn":{"kind":"call","fn":{"kind":"call","fn":{"kind":"input","text":"myBinaryApply","value":{"kind":"name"},"focus":false},"input":{"kind":"input","text":"1","value":{"kind":"literal","type":"Int"},"focus":false}},"input":{"kind":"input","text":"2","value":{"kind":"literal","type":"Int"},"focus":false}},"input":{"kind":"input","text":"addInt","value":{"kind":"name"},"focus":true}},"name":"myBinaryApply","value":{"kind":"lambda","paramName":"x","expr":{"kind":"lambda","paramName":"y","expr":{"kind":"lambda","paramName":"fn","expr":{"kind":"call","fn":{"kind":"call","fn":{"kind":"input","text":"fn","value":{"kind":"name"},"focus":false},"input":{"kind":"input","text":"a","value":{"kind":"text"},"focus":false}},"input":{"kind":"input","text":"b","value":{"kind":"text"},"focus":true}}}}}};