* Re: [Caml-list] function polymorphic in number of arguments?
[not found] <20020917084045.46976.qmail@web11206.mail.yahoo.com>
@ 2002-09-17 15:23 ` Quetzalcoatl Bradley
0 siblings, 0 replies; 4+ messages in thread
From: Quetzalcoatl Bradley @ 2002-09-17 15:23 UTC (permalink / raw)
To: caml-list; +Cc: Noel Welsh
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] function polymorphic in number of arguments?
2002-09-16 12:19 ` Francois Thomasset
@ 2002-09-16 12:24 ` Francois Thomasset
0 siblings, 0 replies; 4+ messages in thread
From: Francois Thomasset @ 2002-09-16 12:24 UTC (permalink / raw)
To: Francois Thomasset; +Cc: Quetzalcoatl Bradley, caml-list, thomasse, thomasse
> > Is it possible to make a function of N arguments (3 or more), the first
> > two are functions of N-2 arguments, and the function calls the first
> > two functions passing its remaining arguments to each of the first two
> > functions.
> What about this one :
> let f a b =
> let g x = a x; b x
> in g;;
>
> François Thomasset
>
Sorry I am wrong : my proposal accepts f f1 f2 "abc",
but fails on f g1 g2 "abc" "def"
FT
-------------------
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] function polymorphic in number of arguments?
2002-09-16 3:44 ` [Caml-list] function polymorphic in number of arguments? Quetzalcoatl Bradley
@ 2002-09-16 12:19 ` Francois Thomasset
2002-09-16 12:24 ` Francois Thomasset
0 siblings, 1 reply; 4+ messages in thread
From: Francois Thomasset @ 2002-09-16 12:19 UTC (permalink / raw)
To: Quetzalcoatl Bradley; +Cc: caml-list, thomasse
> Is it possible to make a function of N arguments (3 or more), the first
> two are functions of N-2 arguments, and the function calls the first
> two functions passing its remaining arguments to each of the first two
> functions.
Whar about this one :
let f a b =
let g x = a x; b x
in g;;
François Thomasset
-------------------
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Caml-list] function polymorphic in number of arguments?
2002-09-15 20:15 [Caml-list] mutually referencing compilation units Henri Dubois-Ferriere
@ 2002-09-16 3:44 ` Quetzalcoatl Bradley
2002-09-16 12:19 ` Francois Thomasset
0 siblings, 1 reply; 4+ messages in thread
From: Quetzalcoatl Bradley @ 2002-09-16 3:44 UTC (permalink / raw)
To: caml-list
Is it possible to make a function of N arguments (3 or more), the first
two are functions of N-2 arguments, and the function calls the first
two functions passing its remaining arguments to each of the first two
functions. For example
let f1 x = print_string (x ^ "1\n");;
let f2 x = print_string (x ^ "2\n");;
let f a b x = ??? What goes here ???
f f1 f2 "abc";;
result in
abc1
abc2
The trick part is I want the same function f to work if I pass it f1
and f2 of 2 arguments and pass 4 arguments to f, f1, f2, and two others
that get passed to f1 and f2.
Thanks for your time,
Quetzalcoatl Bradley
qbradley@blackfen.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
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2002-09-18 18:06 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <20020917084045.46976.qmail@web11206.mail.yahoo.com>
2002-09-17 15:23 ` [Caml-list] function polymorphic in number of arguments? Quetzalcoatl Bradley
2002-09-15 20:15 [Caml-list] mutually referencing compilation units Henri Dubois-Ferriere
2002-09-16 3:44 ` [Caml-list] function polymorphic in number of arguments? Quetzalcoatl Bradley
2002-09-16 12:19 ` Francois Thomasset
2002-09-16 12:24 ` Francois Thomasset
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox