Browse thread
Re: [Caml-list] function polymorphic in number of arguments?
- Quetzalcoatl Bradley
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Quetzalcoatl Bradley <qbradley@b...> |
| 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,
Quetzalcoatl Bradley
qbradley@blackfen.com
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
> --- Quetzalcoatl Bradley <qbradley@blackfen.com>
> 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,
>>
>> Quetzalcoatl Bradley
>> qbradley@newheights.com
>
>
> __________________________________________________
> Do you Yahoo!?
> Yahoo! News - Today's headlines
> http://news.yahoo.com
>
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners