From 5e46faab0f5bc0510298717668c7d8c3d17257e8 Mon Sep 17 00:00:00 2001 From: pimjager Date: Thu, 26 May 2016 16:16:03 +0200 Subject: [PATCH] fold tempTest --- examples/tempTest.spl | 47 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 10 deletions(-) diff --git a/examples/tempTest.spl b/examples/tempTest.spl index 23421f0..a62e6e2 100644 --- a/examples/tempTest.spl +++ b/examples/tempTest.spl @@ -1,17 +1,44 @@ -Let Int a = 4; +//Let Int a = 4;// -mapP1(xs) { - if(isEmpty(xs)) { +//mapP1(xs) { +// if(isEmpty(xs)) { +// return []; +// } else { +// return (xs.hd + 1) : mapP1(xs.tl); +// } +//} +//main() { +// [Int] x = []; +// [Int] y = []; +// Int z = a(); +// x = mapP1(x); +// y = mapP1(x); +// return a() + 5; +//} + +plus(x,y){ + return x+y; +} + +map(f, xs) { + if (isEmpty(xs)) { return []; } else { - return (xs.hd + 1) : mapP1(xs.tl); + return f(xs.hd) : map(f, xs.tl); + } +} + +foldr(f, acc, xs) { + if(isEmpty(xs)) { + return acc; + } else { + return foldr(f, f(xs.hd, acc), xs.tl); } } + main() { - [Int] x = []; - [Int] y = []; - Int z = a(); - x = mapP1(x); - y = mapP1(x); - return a() + 5; + var f = plus(1); + var z = map(f, 1:2:[]); + var x = foldr(plus, 0, 1:2:[]); + return; } \ No newline at end of file -- 2.20.1