views:

119

answers:

2

Many functional programming languages have support for curried parameters. To support currying functions the parameters to the function are essentially a tuple where the last parameter can be omitted making a new function requiring a smaller tuple.

I'm thinking of designing a language that always uses records (aka named parameters) for function parameters.

Thus simple math functions in my make believe language would be:

add { left : num, right : num } = ...
minus { left : num, right : num } = ..

You can pass in any record to those functions so long as they have those two named parameters (they can have more just "left" and "right").

If they have only one of the named parameter it creates a new function:

minus5 :: { left : num } -> num
minus5 = minus { right : 5 }

I borrow some of haskell's notation for above.

Has any one seen a language that does this?

A: 

Sure, Mathematica can do that sort of thing.

High Performance Mark
+4  A: 

OCaml has named parameters and currying is automatic (though sometimes type annotation is required when dealing with optional parameters), but they are not tupled :

    Objective Caml version 3.11.2

# let f ~x ~y = x + y;;
val f : x:int -> y:int -> int = <fun>
# f ~y:5;;
- : x:int -> int = <fun>
# let g = f ~y:5;;
val g : x:int -> int = <fun>
# g ~x:3;;
- : int = 8
ygrek
I have used OCaml a bunch of times a long time and for some reason I thought you could not do that but looks like I am wrong. I wonder if F# can do the same thing?-Thanks
Adam Gent
F# doesn't support named parameters
ygrek
@ygrek I guess its only for Object constructors that you can use named parameters. C# 4.0 will support named parameters :)
Adam Gent
@ygrek I think you might be wrong based on: http://msdn.microsoft.com/en-us/library/dd233213.aspx
Adam Gent
Indeed, F# supports named parameters (in limited form)
ygrek