List Info

Thread: "ocaml_beginners"::[] On applying a polymorphic value to a ploymorphic function




"ocaml_beginners"::[] On applying a polymorphic value to a ploymorphic function
user name
2006-09-26 11:54:08

2006/9/25, doug_arro <doug_arroyahoo.com>:
>; Hi,
>
> On page 76 of the "Developing Applications with Objective OCaml";
> book, it says this:
>;
> "Likewise, when you apply a polymorphic value to a polymorphic
> function, you get a weak type variable, because you must not exclude
&gt; the possibility that the function may construct physically
> modifiable values. In other words, the result of the application is
> always monomorphic"
&gt;
> Then it gives an example like this:
>;
> # (function x -> x) [] ;;
> - : '_a list = []
>
> I tried the same in my OCaml 3.09 on Windows XP but got an different
> result:
&gt;
> # (function x -> x) [] ;;
> - : 'a list = []
>
> As you can see, my version of the OCaml did not produce a week type
> but a strong type "list" instead. I understand that the book result
&gt; is based on OCaml 2.04. So, what has changed in OCaml 3.09 that led
> to such a different result?

What happened? Jacques Garrigue publied an articled "relaspe the
value restriction", and implemented it in ocaml. You could read it
(see http://www.kurims.kyoto-u.ac.jp/preprint/file/RIMS1444.pdf) or I
could try to explain you.

Some polymorphic type are covariant. That mean that if you have a list
of cat, then you also have a list of mamal, because each cat is a
mamal.

Then when the type of a value is computed, if there is a free variable
(as our 'a here), and this variable is in a covariant position, then
recent ocaml will make it fully polimorphic.

Note that for exemple, you still have :
# let f x y = ();;
val f : 'a -> 'b -> unit = <fun>;
# f ();;
- : '_a -> unit = <fun>;
So this does not work for every value (the '_a still exist).

>
> Thanks.
&gt; Doug
>
>
>;
>
&gt;
>
&gt;
> Archives up to August 22, 2005 are also downloadable at http://www.connettivo.net/cntprojects/ocaml_beginners/
> The archives of the very official ocaml list (the seniors' one) can be found at http://caml.inria.fr
> Attachments are banned and you're asked to be polite, avoid flames etc.
> Yahoo! Groups Links
>;
>
&gt;
>
&gt;
>
>
>
>
>

__._,_.___
.

__,_._,___
[1]

about | contact  Other archives ( Real Estate discussion Medical topics )