From 39963b9e830c84e57ab308b7a0efbab329d5f74c Mon Sep 17 00:00:00 2001 From: Matt Bovel <matthieu@bovel.net> Date: Wed, 15 Dec 2021 18:49:59 +0100 Subject: [PATCH] Add solutions of exercise session 11 --- exercises/solution-11.md | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 exercises/solution-11.md diff --git a/exercises/solution-11.md b/exercises/solution-11.md new file mode 100644 index 0000000..60a741b --- /dev/null +++ b/exercises/solution-11.md @@ -0,0 +1,36 @@ +# Exercise Session 11, Solutions + +## Question 1 + +### Question 1.1 + +```scala +def succ = (n => f => x => f(n(f)(x))) +``` + +### Question 1.2 + +```scala +def add = (n => m => n(succ)(m)) +``` + +## Question 2 + +### Question 2.1 + +```scala +def size = (l => l(zero)( h => t => succ(size(t)) )) +``` + +### Question 2.2 + + +```scala +def map = (f => l => l(nil)( h => t => cons( f(h) )( map(f)(t) ) )) +``` + +### Question 2.3 + +```scala +def foldRight = (f => z => l => l(z)( h => t => f(h)(foldRight(f)(z)(t)) )) +``` \ No newline at end of file -- GitLab