From b305de2b1bbf1f5a77e0103764364b1db670cbc2 Mon Sep 17 00:00:00 2001 From: pimjager Date: Thu, 23 Jun 2016 09:45:50 +0200 Subject: [PATCH] stupid higher order functions --- examples/higher.spl | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/examples/higher.spl b/examples/higher.spl index 4fdde0f..c1ad6d6 100644 --- a/examples/higher.spl +++ b/examples/higher.spl @@ -42,6 +42,16 @@ plus(x, y){ return x + y; } +ap(f, x) { return f(x); } + +mapF(f, xs) { + if(isEmpty(xs)) { + return []; + } else { + return (ap(f, xs.hd)) : mapF(f, xs.tl); + } +} + main(){ var x = 5; @@ -50,7 +60,10 @@ main(){ var plus = \x y->x+y; var g = map(plus, [1,2,3]); + var is = mapF(\f->f(1), g); //var is = map(\f->f(1), g); + var p = g.hd; + var q = p(1); //print("is.hd", is.hd); -- 2.20.1