This site is updated infrequently. For up-to-date information, please visit the new OCaml website at ocaml.org.

Re: [Caml-list] function polymorphic in number of arguments?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
 Date: 2002-09-18 (18:06) From: Quetzalcoatl Bradley Subject: Re: [Caml-list] function polymorphic in number of arguments?
```Actually I wanted to pass the same parameters to both g and h but your
solution is obvious and simple.  if all the arguments of g and h are
curried then my generic function always has "one" argument, the tuple
of arguments to g and h, regardless of the size of the tuple.

So my function is
let f a b x = a x; b x;;

and a two argument "a" or "b" would be
let a x = match x with (i,j) -> print_string ("i" ^ "j");;

and I can call it e.g.

f a a ("z","x");;

Thanks,

On Tuesday, September 17, 2002, at 01:40  AM, Noel Welsh wrote:

> You can't have multiple arity functions or tuples in
> O'Caml, but you can curry the functions before calling
> them which is how I'd solve your problem.  You want to
> write something like:
>
>  fun f g h a1 a2 b1 b2 =
>    g a1 a2 ; h b1 b2
>
> with varying numbers of a and b.  Instead you can
> write:
>
>
>  fun f g h a1 b1 =
>     g a1; h b1
>
> and curry additional parameters when you call the
> function:
>
>  f (g a2) (h a2)
>
> This gets the same effect.  Alternatively you can use
> Scheme/Lisp which supports varying arity functions and
> has a handy apply function, for applying varying
> numbers of arguments to a function.
>
> Noel
> wrote:
>> Suppose all the parameters were curried.  Unless I
>> could operate on
>> tuples like they were lists then I would still be in
>> the same boat.  I
>> suppose if there was a tuple->list conversion
>> function I could achieve
>> the effect I desire.  Is there such an operation?
>>
>> Thanks,
>>