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 { GlobalContext } from './GlobalContext';
import { ExprBlock, type ExprBlockState } from './ExprBlock'; import { ExprBlock, type ExprBlockState } from './ExprBlock';
import { extendedEnv } from './EnvContext'; 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"; import { evalEditorBlock } from "./eval";
const commands: [string, string[], string][] = [ const commands: [string, string[], string][] = [
@ -20,6 +20,7 @@ const examples: [string, ExprBlockState][] = [
["function w/ 4 params", tripleFunctionCallEditorState], ["function w/ 4 params", tripleFunctionCallEditorState],
["bigger example" , biggerExample ], ["bigger example" , biggerExample ],
["lambda 2 params" , lambda2Params ], ["lambda 2 params" , lambda2Params ],
["higher order" , higherOrder ],
]; ];
type AppState = { type AppState = {

View file

@ -127,3 +127,5 @@ 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}}}}}};