[
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: | Jean-Christophe Filliatre <Jean-Christophe.Filliatre@l...> |
| Subject: | Re: [Caml-list] Type inference question |
Julien Verlaguet writes:
> I have the following function definition :
>
> let myfun param=
> let res=Marshal.from_channel stdin [] in
> if res=param then
> res
> else res
>
> I was expecting : myfun : 'a -> 'a
>
> I got instead : myfun : 'a -> 'b
>
> Is it normal ?
Yes. "Marshal.from_channel stdin []" has type 'a and this type is
generalized in the let/in construct, giving res the type "forall
'a. 'a". In the test "res = param", the type of res is instanciated on
the type of param, but this does not affect the type of the result.
It would be better if Marshal.from_channel would be given a type that
cannot be generalized ('_a) but I don't think that the ocaml type
system can do this.
Anyway, it is always a good idea to use a type constraint when using
marshalling functions, as in
let (x : tau) = Marshal.from_channel ...
Hope this helps,
--
Jean-Christophe