caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Function call with a list of parameters
@ 2001-12-11 16:31 Vincent Barichard <Vincent Barichard
  2001-12-11 22:59 ` Chris Hecker
  2001-12-12  9:31 ` Jim Farrand
  0 siblings, 2 replies; 16+ messages in thread
From: Vincent Barichard <Vincent Barichard @ 2001-12-11 16:31 UTC (permalink / raw)
  To: caml-list


Hello,

I'm trying to construct a function which take two arguments :
		Arg1 : a function, Arg2 : a list of parameters for the Arg1.
This function will call the function in Arg1 with Arg2 as parameters.

For example :
If I have the function
	 let fourAdd x y z w = x + y + z + w;;

I'll can execute it with the next command line :
	 myFunctionCall fourAdd [1 ; 2 ; 3 ; 4];;

The hypothesis are :
- The Arg1 function is in curried form and all its arguments have the same
type.
- The length of Arg2 is exactly the number of arguments needed by Arg1

I've tried the following code, but it doesn't work because the argument
nomProcedure has a different type at each call.

let rec runAlgoWithArgs nomProcedure liste_Args =
	match liste_Args with
		[] -> raise Exit
	|	[x] -> nomProcedure x
	|	x::xs -> runAlgoWithArgs (nomProcedure x) xs

Is anybody has an idea ??

Thanks for your help,

Vincent

-- 
Vincent Barichard
Métaheuristiques et Optimisation Combinatoire
Faculté des Sciences d'Angers
Tel : 02 41 73 52 06
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [Caml-list] Function call with a list of parameters
  2001-12-11 16:31 [Caml-list] Function call with a list of parameters Vincent Barichard <Vincent Barichard
@ 2001-12-11 22:59 ` Chris Hecker
  2001-12-11 23:26   ` Bruce Hoult
                     ` (3 more replies)
  2001-12-12  9:31 ` Jim Farrand
  1 sibling, 4 replies; 16+ messages in thread
From: Chris Hecker @ 2001-12-11 22:59 UTC (permalink / raw)
  To: Vincent.Barichard, caml-list


>I'm trying to construct a function which take two arguments :
>                Arg1 : a function, Arg2 : a list of parameters for the Arg1.
>This function will call the function in Arg1 with Arg2 as parameters.

This is slightly related to a feature I'd like that's easy to do in lisp, but I don't think there's a way to do it in ML-style languages:

I have a function that returns a tuple, and a function that takes two curried parameters.  I'd like to pass the results of the first to the second, without having to break up the tuple with fst and snd (or pattern matching).

let f () = (1,2)
let g x y = x + y

g (? f ())

vs.

let x,y = f () in
g x y

With lisp you can just "apply" and it works.  There's no way in caml to spread the arguments into a curried function application, however.

Chris


-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [Caml-list] Function call with a list of parameters
  2001-12-11 22:59 ` Chris Hecker
@ 2001-12-11 23:26   ` Bruce Hoult
  2001-12-12  9:35   ` Markus Mottl
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 16+ messages in thread
From: Bruce Hoult @ 2001-12-11 23:26 UTC (permalink / raw)
  To: Chris Hecker, Vincent.Barichard, caml-list

At 2:59 PM -0800 11/12/01, Chris Hecker wrote:
>  >I'm trying to construct a function which take two arguments :
>>                 Arg1 : a function, Arg2 : a list of parameters for the Arg1.
>>This function will call the function in Arg1 with Arg2 as parameters.
>
>This is slightly related to a feature I'd like that's easy to do in 
>lisp, but I don't think there's a way to do it in ML-style languages:
>
>I have a function that returns a tuple, and a function that takes 
>two curried parameters.  I'd like to pass the results of the first 
>to the second, without having to break up the tuple with fst and snd 
>(or pattern matching).
>
>let f () = (1,2)
>let g x y = x + y
>
>g (? f ())
>
>vs.
>
>let x,y = f () in
>g x y
>
>With lisp you can just "apply" and it works.  There's no way in caml 
>to spread the arguments into a curried function application, however.

No, that's not the case.  "Apply" needs a list, but multiple valued 
function result is NOT a list.  It will be treated by "apply" as 
being just the first value.

bruce@k7:~ > cmucl
CMU Common Lisp 18c, running on k7
Send questions and bug reports to your local CMU CL maintainer,
or to cmucl-help@cons.org. and cmucl-imp@cons.org. respectively.
Loaded subsystems:
     Python 1.0, target Intel x86
     CLOS based on PCL version:  September 16 92 PCL (f)
* (defun f () (values 1 2))

F
* (defun g (x y) (+ x y))

G
* (apply #'g '(1 2))

3
* (apply #'g (f))

Type-error in KERNEL::OBJECT-NOT-LIST-ERROR-HANDLER:  1 is not of type LIST


I'm not quite sure off the top of my head the correct thing to do in 
Common Lisp, but it will be similar to the Dylan:

    define function f() values(1, 2) end;
    define function g(x, y) x + y end;

    let (#rest results) = f();
    apply(g, results);


Ah, here we go, in Common Lisp.  Either...

    (apply #'g (multiple-value-list (f)))

... or ...

    (multiple-value-call #'g (f))


Hope this helps.

-- Bruce
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [Caml-list] Function call with a list of parameters
  2001-12-11 16:31 [Caml-list] Function call with a list of parameters Vincent Barichard <Vincent Barichard
  2001-12-11 22:59 ` Chris Hecker
@ 2001-12-12  9:31 ` Jim Farrand
  1 sibling, 0 replies; 16+ messages in thread
From: Jim Farrand @ 2001-12-12  9:31 UTC (permalink / raw)
  To: Vincent.Barichard; +Cc: caml-list

On Tuesday 11 December 2001 16:31, you wrote:

> I'm trying to construct a function which take two arguments :
> 		Arg1 : a function, Arg2 : a list of parameters for the Arg1.
> This function will call the function in Arg1 with Arg2 as parameters.

I'm not much of an OCaml expert, but I suspect that what you are trying to do 
is not possible.

Imagine that you had defined such a function, and want to call it like this:

> 	 myFunctionCall f l

What would be the type of f?  It depends on l:

If l is [],  f has type 'a

If l is [1], f has type int -> 'a

If l is [1; 2], f has type int -> int -> 'a

etc.

I don't think OCaml can properly type a function like you are describing.

Regards,
Jim
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [Caml-list] Function call with a list of parameters
  2001-12-11 22:59 ` Chris Hecker
  2001-12-11 23:26   ` Bruce Hoult
@ 2001-12-12  9:35   ` Markus Mottl
  2001-12-12 10:20   ` Vincent Barichard <Vincent Barichard
  2001-12-12 13:52   ` Francois Pottier
  3 siblings, 0 replies; 16+ messages in thread
From: Markus Mottl @ 2001-12-12  9:35 UTC (permalink / raw)
  To: Chris Hecker; +Cc: Vincent.Barichard, caml-list

On Tue, 11 Dec 2001, Chris Hecker wrote:
> I have a function that returns a tuple, and a function that takes
> two curried parameters.  I'd like to pass the results of the first
> to the second, without having to break up the tuple with fst and snd
> (or pattern matching).

  let uncurry f (x, y) = f x y

> let f () = (1,2)
> let g x y = x + y
> 
> g (? f ())

  uncurry g (f ())

Regards,
Markus Mottl

-- 
Markus Mottl                                             markus@oefai.at
Austrian Research Institute
for Artificial Intelligence                  http://www.oefai.at/~markus
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [Caml-list] Function call with a list of parameters
  2001-12-11 22:59 ` Chris Hecker
  2001-12-11 23:26   ` Bruce Hoult
  2001-12-12  9:35   ` Markus Mottl
@ 2001-12-12 10:20   ` Vincent Barichard <Vincent Barichard
  2001-12-12 22:31     ` Diego Olivier Fernandez Pons
  2001-12-12 13:52   ` Francois Pottier
  3 siblings, 1 reply; 16+ messages in thread
From: Vincent Barichard <Vincent Barichard @ 2001-12-12 10:20 UTC (permalink / raw)
  To: caml-list

Thank you, I'll try another way...

Vincent

Chris Hecker wrote:

> 
> >I'm trying to construct a function which take two arguments :
> >                Arg1 : a function, Arg2 : a list of parameters for the Arg1.
> >This function will call the function in Arg1 with Arg2 as parameters.
> 
> This is slightly related to a feature I'd like that's easy to do in lisp, but I don't think there's a way to do it in ML-style languages:
> 
> I have a function that returns a tuple, and a function that takes two curried parameters.  I'd like to pass the results of the first to the second, without having to break up the tuple with fst and snd (or pattern matching).
> 
> let f () = (1,2)
> let g x y = x + y
> 
> g (? f ())
> 
> vs.
> 
> let x,y = f () in
> g x y
> 
> With lisp you can just "apply" and it works.  There's no way in caml to spread the arguments into a curried function application, however.
> 
> Chris
> 
> 
> -------------------
> Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
> To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr

-- 
Vincent Barichard
Métaheuristiques et Optimisation Combinatoire
Faculté des Sciences d'Angers
Tel : 02 41 73 52 06
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [Caml-list] Function call with a list of parameters
  2001-12-11 22:59 ` Chris Hecker
                     ` (2 preceding siblings ...)
  2001-12-12 10:20   ` Vincent Barichard <Vincent Barichard
@ 2001-12-12 13:52   ` Francois Pottier
  2001-12-12 18:54     ` Chris Hecker
  3 siblings, 1 reply; 16+ messages in thread
From: Francois Pottier @ 2001-12-12 13:52 UTC (permalink / raw)
  To: caml-list


On Tue, Dec 11, 2001 at 02:59:22PM -0800, Chris Hecker wrote:

> I have a function that returns a tuple, and a function that takes two
> curried parameters.  I'd like to pass the results of the first to the
> second, without having to break up the tuple with fst and snd (or pattern
> matching).
> 
> let f () = (1,2)
> let g x y = x + y

The usual solution is as follows:

  # let uncurry g (x,y) = g x y;;
  val uncurry : ('a -> 'b -> 'c) -> 'a * 'b -> 'c = <fun>
  # uncurry g (f());;
  - : int = 3

-- 
François Pottier
Francois.Pottier@inria.fr
http://pauillac.inria.fr/~fpottier/
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [Caml-list] Function call with a list of parameters
  2001-12-12 13:52   ` Francois Pottier
@ 2001-12-12 18:54     ` Chris Hecker
  2001-12-12 19:04       ` Patrick M Doane
                         ` (2 more replies)
  0 siblings, 3 replies; 16+ messages in thread
From: Chris Hecker @ 2001-12-12 18:54 UTC (permalink / raw)
  To: Francois.Pottier, caml-list


>The usual solution is as follows:
>  # let uncurry g (x,y) = g x y;;
>  val uncurry : ('a -> 'b -> 'c) -> 'a * 'b -> 'c = <fun>
>  # uncurry g (f());;
>  - : int = 3

Sure, but if I have a function that's like this:

let f blah = (x,y)
let g a b x y c d = ...

Then I need to write a new uncurry to pass x y into the right parameters in g.  At which point it's easier to just do the "let x,y = f blah in" construct.

I'm not saying the lack of this feature is a showstopper or anything, but since the other guy brought it up, I figured I'd post about it since it's kind of bothered me for a while.  :)  

It does seem like there's an asymmetry in parameters versus return values that might be worth looking into (in languages in general, not just caml).  Bruce's example was interesting to me because I didn't know that lisp had tuples (as opposed to just lists).  That reintroduces the asymmetry that I'm talking about, where if everything was just a list (both returns and params) then it would be symmetric and apply would just work.  Even with tuples, lisp is still more symmetric since you can convert a tuple to a list generically and then pass it in with apply (according to Bruce's example).

I would assume people way more knowledgable than me have analyzed the tradeoffs in the [a]symmetry before.  Assuming it's interesting at all, which I don't know enough about languages to know that either.  :)

Chris

-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [Caml-list] Function call with a list of parameters
  2001-12-12 18:54     ` Chris Hecker
@ 2001-12-12 19:04       ` Patrick M Doane
  2001-12-12 23:49       ` Bruce Hoult
  2001-12-13  7:41       ` Francois Pottier
  2 siblings, 0 replies; 16+ messages in thread
From: Patrick M Doane @ 2001-12-12 19:04 UTC (permalink / raw)
  To: Chris Hecker; +Cc: Francois.Pottier, caml-list

On Wed, 12 Dec 2001, Chris Hecker wrote:

>
> It does seem like there's an asymmetry in parameters versus return
> values that might be worth looking into (in languages in general, not
> just caml).  Bruce's example was interesting to me because I didn't
> know that lisp had tuples (as opposed to just lists).  That
> reintroduces the asymmetry that I'm talking about, where if everything
> was just a list (both returns and params) then it would be symmetric
> and apply would just work.  Even with tuples, lisp is still more
> symmetric since you can convert a tuple to a list generically and then
> pass it in with apply (according to Bruce's example).

I understand your point and mostly agree with it, but keep in mind that:

  let f x y = (x,y)

is not a function that takes 2 parameters. So, I would say that Caml is
symmetric if you don't curry the arguments.

Also, the style of currying everything is a little different in the SML
community. Their compilers often expect (and optimize for) multiple
parameters as tuples.

Patrick

-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [Caml-list] Function call with a list of parameters
  2001-12-12 10:20   ` Vincent Barichard <Vincent Barichard
@ 2001-12-12 22:31     ` Diego Olivier Fernandez Pons
  2001-12-13  0:20       ` Bruno Pagano
  0 siblings, 1 reply; 16+ messages in thread
From: Diego Olivier Fernandez Pons @ 2001-12-12 22:31 UTC (permalink / raw)
  To: Vincent.Barichard; +Cc: Caml

Vincent Barichard a écrit

let fourAdd x y z w = x + y + z + w;;
myFunctionCall fourAdd [1 ; 2 ; 3 ; 4];;
#   - : int = 10

On a effectivement un problème de typage de la fonction donnée en
argument (puisque le type "fonction" sans précision d'arité n'existe
pas en Caml). Si le code suivant marche, on est immédiatement en
difficultés quand on veut changer le nombre d'arguments (même dans un
cas fini).

let applique f = function
  | [x; y; z; t] -> f x y z t
  | _ -> failwith "type error"
;;

applique addfour [1; 2; 3; 4];;
#   - : int = 10

let applique f = function
  | [x; y; z] -> f x y z
  | [x; y; z; t] -> f x y z t
  | _ -> failwith "type error"
;;

# This expression has type 'a but is here used with type 'b -> 'a

Une première idée serait de passer par un type somme

type fonction =
  | Unaire of (int -> int)
  | Binaire of (int -> int -> int)
  | Ternaire of (int -> int -> int -> int)
;;

puis faire un filtrage dans lors le l'application

let appliquer f liste =
  match f with
  | Unaire g -> let [x] = liste in g x
  | Binaire g -> let [x; y] = liste in g x y
;;

Outre les avertissements que génère le code et la complication que
requiert le passage au type somme proposé, ce code a le grand
désavantage d'imposer que l'arité de f soit bornée.

Peut on contourner la difficulté ? On remarquera que l'on peut écrire
différemment le cas particulier que vous avez proposé :

let add x total = x + total;;
let addFour x y z t = add x (add y (add z (add t 0)));

Et appliquer la fonction add sur une liste de longueur quelconque est
tout à fait possible.

Peut-on éviter d'appliquer à chaque étape la même fonction ? oui !

let add2 x total = total + x + 2;;
let add3 x total = total + x + 3;;
let add5 x total = total + x + 5;;
let add7 x total = total + x + 7;;

let add17 x y z t = add2 x (add3 y (add5 z (add7 t 0)));;

Si l'on dispose d'une liste de fonctions, on peut sans difficulté
l'appliquer au moyen de :

let rec applique_fonctions argument = function
  | [] -> argument
  | (tete :: queue) -> applique_fonctions (tete argument) queue
;;

# val applique_fonctions : 'a -> ('a -> 'a) list -> 'a = <fun>

Autrement dit, si vous arrivez à transformer votre fonction à n
arguments en composée de n fonctions d'arité fixe, vous pourrez alors
 les appliquer à une liste de n paramètres indépendamment de n.
Cela dit, ce dernier problème n'est ni plus aisé, ni toujours soluble.

        Diego Olivier

-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [Caml-list] Function call with a list of parameters
  2001-12-12 18:54     ` Chris Hecker
  2001-12-12 19:04       ` Patrick M Doane
@ 2001-12-12 23:49       ` Bruce Hoult
  2001-12-13  7:41       ` Francois Pottier
  2 siblings, 0 replies; 16+ messages in thread
From: Bruce Hoult @ 2001-12-12 23:49 UTC (permalink / raw)
  To: Chris Hecker, Francois.Pottier, caml-list

At 10:54 AM -0800 12/12/01, Chris Hecker wrote:
>It does seem like there's an asymmetry in parameters versus return 
>values that might be worth looking into (in languages in general, 
>not just caml).  Bruce's example was interesting to me because I 
>didn't know that lisp had tuples (as opposed to just lists).  That 
>reintroduces the asymmetry that I'm talking about, where if 
>everything was just a list (both returns and params) then it would 
>be symmetric and apply would just work.  Even with tuples, lisp is 
>still more symmetric since you can convert a tuple to a list 
>generically and then pass it in with apply (according to Bruce's 
>example).
>
>I would assume people way more knowledgable than me have analyzed 
>the tradeoffs in the [a]symmetry before.  Assuming it's interesting 
>at all, which I don't know enough about languages to know that 
>either.  :)

This asymmetry was one of the motivating insights behind the design 
of Scheme in the late 1970's, and both Dylan and Common Lisp have to 
some extent followed it.

If you write programs in Continuation Passing Style (CPS) then there 
is no asymmetry between parameter passing and return value passing, 
and many Scheme (and *ML) compilers convert programs to CPS in the 
process of compilation.  Scheme provides constructs to allow the user 
to write a mix of CPS and normal code (call/cc) while CL and Dylan 
provide more explicit support for multiple return values.  Scheme 
recently added similar support.

-- Bruce
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [Caml-list] Function call with a list of parameters
  2001-12-13  0:20       ` Bruno Pagano
@ 2001-12-13  0:17         ` Diego Olivier Fernandez Pons
  2001-12-14 13:26           ` Alain Frisch
  0 siblings, 1 reply; 16+ messages in thread
From: Diego Olivier Fernandez Pons @ 2001-12-13  0:17 UTC (permalink / raw)
  To: Bruno Pagano; +Cc: Caml

Bruno Pagano a écrit :

> Thanks to OOP in caml, we can use cyclics types (-rectypes option)

J'aurais nonobstant une question : quel lien avec la POO ?

I am afraid I do not understand how are cyclic types and OOP related.
Could you explain more precisely this point ?

        Diego Olivier


-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [Caml-list] Function call with a list of parameters
  2001-12-12 22:31     ` Diego Olivier Fernandez Pons
@ 2001-12-13  0:20       ` Bruno Pagano
  2001-12-13  0:17         ` Diego Olivier Fernandez Pons
  0 siblings, 1 reply; 16+ messages in thread
From: Bruno Pagano @ 2001-12-13  0:20 UTC (permalink / raw)
  To: Diego Olivier Fernandez Pons; +Cc: Vincent.Barichard, Caml

On Wed, Dec 12, 2001 at 11:31:53PM +0100, Diego Olivier Fernandez Pons wrote:

One wants write the following function 

# let rec app f  = function 
    [] -> f 
  | x::l -> app (f x) l    ;;

but caml reply :

This expression has type 'a but is here used with type 'b -> 'a


Thanks to OOP in caml ;-) , we can use cyclics types (-rectypes option)
and now :

# let rec app f  = function 
    [] -> f 
  | x::l -> app (f x) l    ;;
val app : ('b -> 'a as 'a) -> 'b list -> 'a = <fun>


So what about the first argument of app. I need a function with 'a -> 'b
as type, it must be a function with no termination. Ok, the result may
be raised by an exception.
For instance :

exception Int of int

# let sum2 x y = raise (Int (x+y))
  let sum3 x y z = raise (Int (x+y+z)) ;;
val sum2 : int -> int -> 'a = <fun>
val sum3 : int -> int -> int -> 'a = <fun>

To end, the apply function will catch the result :

# let  apply  f l = try app f l ; 0 with Int x -> x ;;
Warning: this function application is partial,
maybe some arguments are missing.
val apply : ('b -> 'a as 'a) -> 'b list -> int = <fun>

We are more intelligent than the type checker and we ommit the warning ...

and now let's try :

# apply sum2 [1;2] ;;
- : int = 3

# apply sum3 [1;2;3] ;;
- : int = 6


Bruno Pagano
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [Caml-list] Function call with a list of parameters
  2001-12-12 18:54     ` Chris Hecker
  2001-12-12 19:04       ` Patrick M Doane
  2001-12-12 23:49       ` Bruce Hoult
@ 2001-12-13  7:41       ` Francois Pottier
  2 siblings, 0 replies; 16+ messages in thread
From: Francois Pottier @ 2001-12-13  7:41 UTC (permalink / raw)
  To: caml-list


> Sure, but if I have a function that's like this:
> 
> let f blah = (x,y)
> let g a b x y c d = ...
> 
> Then I need to write a new uncurry to pass x y into the right parameters in g.

Or you could keep the same definition of uncurry and write

  uncurry (g a b) (f blah) c d

So the same operator works as long as x and y are *two* *consecutive*
parameters to g. That said, I'm not sure how readable (or efficient)
this style is.

-- 
François Pottier
Francois.Pottier@inria.fr
http://pauillac.inria.fr/~fpottier/
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [Caml-list] Function call with a list of parameters
  2001-12-13  0:17         ` Diego Olivier Fernandez Pons
@ 2001-12-14 13:26           ` Alain Frisch
  2001-12-17  7:40             ` Francois Pottier
  0 siblings, 1 reply; 16+ messages in thread
From: Alain Frisch @ 2001-12-14 13:26 UTC (permalink / raw)
  To: Diego Olivier Fernandez Pons; +Cc: Bruno Pagano, Caml

On Thu, 13 Dec 2001, Diego Olivier Fernandez Pons wrote:

> I am afraid I do not understand how are cyclic types and OOP related.
> Could you explain more precisely this point ?

Cyclic (aka recursive) types are necessary to type such an expression:
# fun x -> x # run (); x;;
- : (< run : unit -> 'b; .. > as 'a) -> 'a = <fun>

Note that recursive constructed (variant,record) types are not considered
cyclic:  type 'a tree = Leaf | Node of 'a * 'a. Except for objects,
recursive types are often unecessary; allowing them may hide or deplace
type errors, and make error messages difficult to understand. Moreover,
they sensibly complexify the implementation. I don't want to speak for the
OCaml team, but it seems reasonnable to consider that recursive types are
supported in OCaml only because of OOP ...



Alain

-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [Caml-list] Function call with a list of parameters
  2001-12-14 13:26           ` Alain Frisch
@ 2001-12-17  7:40             ` Francois Pottier
  0 siblings, 0 replies; 16+ messages in thread
From: Francois Pottier @ 2001-12-17  7:40 UTC (permalink / raw)
  To: caml-list


Hello,

Alain Frisch wrote:
> Cyclic (aka recursive) types are necessary to type such an expression:
> # fun x -> x # run (); x;;
> - : (< run : unit -> 'b; .. > as 'a) -> 'a = <fun>

This is slightly misleading. Such a type is really non-recursive, since
it is an abbreviation for the following:

  < run : unit -> 'b; 'c > -> < run : unit -> 'b; 'c >

The notation (t as 'a) allows sharing relationships to appear explicitly
in print, yielding shorter and more readable types. It actually describes
a recursive type only when 'a occurs within t, which is not the case in
the example above. It happens e.g. when x is passed as a parameter to
one of its own methods:

  # fun x -> x#compare(x);;
  - : (< compare : 'a -> 'b; .. > as 'a) -> 'b = <fun>

-- 
François Pottier
Francois.Pottier@inria.fr
http://pauillac.inria.fr/~fpottier/
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2001-12-17  7:40 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-12-11 16:31 [Caml-list] Function call with a list of parameters Vincent Barichard <Vincent Barichard
2001-12-11 22:59 ` Chris Hecker
2001-12-11 23:26   ` Bruce Hoult
2001-12-12  9:35   ` Markus Mottl
2001-12-12 10:20   ` Vincent Barichard <Vincent Barichard
2001-12-12 22:31     ` Diego Olivier Fernandez Pons
2001-12-13  0:20       ` Bruno Pagano
2001-12-13  0:17         ` Diego Olivier Fernandez Pons
2001-12-14 13:26           ` Alain Frisch
2001-12-17  7:40             ` Francois Pottier
2001-12-12 13:52   ` Francois Pottier
2001-12-12 18:54     ` Chris Hecker
2001-12-12 19:04       ` Patrick M Doane
2001-12-12 23:49       ` Bruce Hoult
2001-12-13  7:41       ` Francois Pottier
2001-12-12  9:31 ` Jim Farrand

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).