Embrace the multi-argument, multi-value nature of Common Lisp in Coalton #162
johnwcowan
started this conversation in
Ideas and Proposals
Replies: 1 comment 1 reply
-
Just for posterity: Coalton does embrace Lisp's multi-argument functions (but not, as you mention, any interplay between multi-argument and multi-value). It will define curried functions as ordinary N-ary Lisp functions, and make the function calls ordinary N-ary function calls if N arguments are supplied. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Functions in most FP languages accept only one argument because they can only deliver one result, and we want functions to be composable. For practical purposes, though, we need to be able to write multi-argument functions, so we emulate them in ML and Haskell by currying.
But in CL (and in Scheme) we can compose a multi-value operand with a multi-argument function, and all will be well! We can write the type of a function as
Foo -> Foo -> (Foo -> Foo)
, which means a two-argument function that returns two values. As a degenerate case, we can writeFoo -> Foo -> Foo
, which meansFoo -> Foo -> (Foo)
.Now suppose we have two functions
foo
andbar
, both of typeInteger -> Float -> (Float -> Integer)
. How do we writefoo
? An expression in tail context (determined statically) must be(values anInt aFloat anInt)
, and this is the only way we can usevalues
. Of course we can also call a function whose return types areInteger-> Float
in tail position instead.'If we write
(baz (foo 10 20) (baz (50 100))
in an integer context, what is the inferred type ofbaz
? The answer isInteger -> Float -> Integer -> Float -> Integer)
. (We implement this usingmultiple-value-call
under the table.)Now currying is also useful to reduce the argument arity of a called function. We can simulate this by using the Scheme macro
cut
. A call to(cut zizzle 10 <> aString 20.0)
, wherezizzle
has the typeInt -> String -> Float -> ...
, expands to(lambda (a b) (zizzle 10 aString 20.0))
. You can have any number of<>
pseudo-arguments from none to all of them (if you want to reorder them, uselambda
instead). There should also be an easy way to expand the return arity, perhaps by writing(values (baz 10 20) "x")
with return type(Float -> Integer -> String)
.I don't know how much of a Big Deal this is to implement: maybe just a little, maybe pervasively.
Beta Was this translation helpful? Give feedback.
All reactions