Question: Computer Science ConnectionsCurryingFor a binary predicate P ( x , y ) in an expression like 8 y : 8 x : P ( x
Computer Science ConnectionsCurryingFor a binary predicate Px y in an expression like y : x : Px y we can think of this expression as frst pluggingin a value for y which then yields a unary predicate x : Px ywhich takes an argument x Theres an interestingparallel between this view of nested quantifers and a way of writing functions in some programming languages M L fun sum a b a b;A quick note on ML syntax:fun is a keyword that sayswere defning a function; sumis the name of it; a b is thelist of arguments; and thatfunction is defned to returnthe value of ab sum ; returns sum ; returns # Python def sumab: return ab sum # returns sum # returns ; Schemedefine sumlambda a b a bFor Scheme: lambda argsbody denotes the functionthat takes arguments args andreturns the value of thefunction body body. Also,Scheme is a prefx language,so applying the function f toarguments arg argargN is written f arg arg argN; for example, has the value sum ;; returns sum ;; returns Figure A sum function, implemented in three languages.For concreteness, lets think about a smallfunction that takes two arguments and justreturns their sum. Figure shows implementations of this function in three differentprogramming languages, and then uses sumto actually compute and But now suppose that we want to defne afunction that takes one argument and adds to it Can we make use of the sum functionto do soThe analogy to predicates is thattaking a twoargument predicate and applying it to one argument gives oneargumentpredicate; here were trying to take a twoargument function in a programming language and apply it to one argument to yield aoneargument function. The answer is yesand it turns out that creating the add function using sum is very easy in ML: we simply apply sum to one argument, and the result is a function thatstill wants one more argument. To do this, we execute val add sum ; which defnes a value thats the valpart of the syntax whose name is add and whose value is sum applied to That makes add a oneargumentfunction, and now add has the value ; add has the value ; and add has the value fun sum a b a b; val add sum ; sum ; returns add; returns def suma: def sumAb: return ab return sumA add sum sum # returns add # returns define sum lambda alambda b a bDefne sum to be a functionthat takes an argument a andreturns the function that takes anargument b and returns abThis function taking breturning ab is called sumAin the Python code, and isunnamed in the Schemecode.define addsum sum ;; returns add ;; returns Figure Curried implementations of sum.A function like sum in ML which takes itsmultiple arguments one at a time, is said tobe Curriedafter the logician Haskell CurryAs usual, theres a richer history than a concept named after one personwould suggest: the idea dates back at least toMoses Schnfnkel and GottlobFrege two earlier logiciansThe programming language Haskell is alsonamed in Currys honor. Thinking about Curried functions is a classical topic in the studyof programming languages. Currying canbe very handy in programmingparticularlywhen you have one parameter to a functionthat stays the same for many different calls.......This is a discrete math class, we have to show computer science is related to this
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
