From 0b8bd8e88f2620992310c7ba41283f5d9120e371 Mon Sep 17 00:00:00 2001 From: Peter Mikkelsen Date: Sun, 9 Jan 2022 22:24:07 +0000 Subject: Add rule for monadic function application --- eval.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'eval.c') diff --git a/eval.c b/eval.c index 9c737ff..da49137 100644 --- a/eval.c +++ b/eval.c @@ -9,11 +9,12 @@ Rune *errormsg; typedef Datum (*evalfn)(Datum, Datum); Datum strand(Datum, Datum); +Datum monadfun(Datum, Datum); int bindingstrengths[12][12] = { /* A F H MO DO AF ( ) { } [ ] */ - 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* A */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* F */ + 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* A */ + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* F */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* H */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* MO */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* DO */ @@ -29,7 +30,7 @@ int bindingstrengths[12][12] = { evalfn evalfns[12][12] = { /* A F H MO DO AF ( ) { } [ ] */ strand, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* A */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* F */ + monadfun, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* F */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* H */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* MO */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* DO */ @@ -90,4 +91,15 @@ strand(Datum left, Datum right) result.tag = ArrayTag; result.array = fnCatenateFirst(left.array,fnEnclose(right.array)); return result; +} + +Datum +monadfun(Datum left, Datum right) +{ + print("Monadic function application\n"); + Datum result; + result.tag = ArrayTag; + /* TODO handle undefined functions here */ + result.array = monadfunctiondefs[left.code](right.array); + return result; } \ No newline at end of file -- cgit v1.2.3