Is there a way to get the curried form of binary operators in SML / NJ?

For example, instead of

- op =;
val it = fn : ''a * ''a -> bool

I would prefer

- op =;
val it = fn : ''a -> ''a -> bool

for use in

val x = getX()
val l = getList()
val l' = if List.exists ((op =) x) l then l else x::l

Obviously, I can do it myself, for example,

val l' = if List.exists (fn y => x = y) l then l else x::l

but I want to make sure that I don’t miss a more elegant way.

+3
source share
2 answers

You can write a helper function that performs the function:

fun curry f x y = f (x, y)

Then you can do something like

val curried_equals = curry (op =)
val l' = if List.exists (curried_equals x) l then l else x::l
+5
source

My knowledge of SML is scarce, but I looked through the Ullman book and couldn't find an easy way to convert a function that takes a tuple to a curried function. They have two different signatures and cannot be directly compatible with each other.

, .

Haskell.

: , , , . SML , , . , . , . ​​ . , .

, , curried. , ( ), .

+2

Source: https://habr.com/ru/post/1717026/


All Articles