Feed on
Posts
Comments

Currying

I’ve been playing around with the ML language recently, using the OCaml implementation.

Picking up ML illustrates to me why it’s useful to learn a number of different languages in order to experience various styles of programming - it’s sometimes not enough that a language merely ’supports’ a particular style; sometimes the language must live that style for the user to fully get it.

For example, lots of languages support ‘currying‘ of functions by allowing the user to return anonymous closures. However ML is the first language I’ve used that embraces currying as the basis for implementing multi-argument functions - i.e. in ML, multi-argument functions are literally just nested single argument functions.

For example, in the following expression:


let sum = fun i j -> i + j

the type of ’sum’ is:


int -> int -> int

..meaning that ’sum’ is a function that takes an integer and returns a function which takes an integer and returns an integer.

In addition OCaml’s function-call syntax doesn’t use brackets, which allows the call to be considered by the user as both as a multiple-arg function call or as a bunch of nested calls.
E.g. in


sum 3 4

the above could be read either as ‘invoke the ’sum’ function with the arguments 3 and 4′, or alternatively as ‘invoke the ’sum’ function with an argument 3, and then invoke the result of that with the argument 4′.

Viewing 1 Comment

close Reblog this comment
blog comments powered by Disqus

generic acomplia purchase cialis overnight delivery cheap acomplia online buy generic clomid buy cialis low price viagra without prescription where to buy cialis lowest price levitra where to buy propecia cheap cialis from canada lasix no prescription viagra without rx cheap accutane tablets viagra online without prescription viagra no rx buying cialis online zithromax viagra in uk free cialis cialis us where to buy acomplia find cialis online buy viagra lowest price accutane prescription buy cheap accutane online cialis buy buy generic cialis online acomplia order propecia online lowest price synthroid synthroid without a prescription synthroid online buy propecia online cheap levitra online where to buy levitra cialis online review synthroid prices cialis generic cialis buy drug buy viagra on line viagra pharmacy cialis for order price of levitra zithromax online where to buy synthroid soma generic generic clomid propecia online stores viagra cheap drug cheap generic soma cialis cheap zithromax online cheap order accutane online purchase zithromax online purchase viagra online buy cheap clomid cheap generic propecia zithromax pharmacy online pharmacy cialis cheapest acomplia cost of cialis no prescription viagra free viagra purchase lasix online cialis from india viagra from india order discount cialis soma online stores find no rx cialis cialis no rx required find viagra without prescription approved cialis pharmacy lasix discount