From d8a9d686243baf9063910c55d304b6c8b4932e3b Mon Sep 17 00:00:00 2001 From: fredrikr79 Date: Sun, 28 Sep 2025 14:57:02 +0200 Subject: [PATCH] task 4 - quadratic polynomial currying --- assignment3/main.oz | 8 ++++++++ assignment3/report.md | 12 ++++++++++++ 2 files changed, 20 insertions(+) diff --git a/assignment3/main.oz b/assignment3/main.oz index ed673c2..20b6e54 100644 --- a/assignment3/main.oz +++ b/assignment3/main.oz @@ -87,3 +87,11 @@ local Iota Product Factorial in {System.show {Factorial 5}} end +% task 4 +fun {Quadratic A B C} + fun {$ X} A*X*X + B*X + C end +end +{System.show '3*2^2 + 2*2 + 1 ='} +{System.show {{Quadratic 3 2 1} 2}} + + diff --git a/assignment3/report.md b/assignment3/report.md index ffadebb..29186e7 100644 --- a/assignment3/report.md +++ b/assignment3/report.md @@ -127,3 +127,15 @@ end {System.show {Factorial 5}} % -> 5! = 120 ``` +## task 4 + +trivially curried* function + +```oz +fun {Quadratic A B C} + fun {$ X} A*X*X + B*X + C end +end +``` + +*: Quadratic is of arity 3, but could be thought of as arity 4 if you consider the argument of it's returned function as well. all functions of arity greater than 1 can be thought of as functions returning functions composed with each other: currying. named after Haskell Curry. +