On Wed, 6 Jul 2011, Jacques Garrigue wrote:

> On 2011/07/05, at 22:59, malc wrote:
> 
> > Perhaps someone could explain why following behaves the way it does:
> > 
> > ~$ ocaml
> >        Objective Caml version 3.11.2
> > 
> > # let f ic = let i = input_value ic in let j = i + 1 in LargeFile.seek_in 
> > ic i;;
> > Warning Y: unused variable j.
> > val f : in_channel -> unit = <fun>
> 
> The return type of input_value being 'a, which gets generalized by the
> relaxed value restriction, i gets the polymorphic type "forall 'a. 'a".
> So you can use it both as an int and an int64.
> ==> input_value is an unsafe function, you should always write a type
>       annotation on its return type.

Sure i'm well aware of that, but to me "let j = i + 1" means that i has
type int and after that "LargeFile.seek ic i" makes no sense yet is
accepted by the type checker.

> 
> > # let f ic = let i = input_value ic in let j = i + 1 in LargeFile.seek_in 
> > ic j;;
> > Error: This expression has type int but an expression was expected of type
> >         int64
> 
> j being the result of an integer addition, it has type int, and cannot be used
> as int64.
> 
> Jacques
> 
> 

-- 
mailto:[email protected]

-- 
Caml-list mailing list.  Subscription management and archives:
https://sympa-roc.inria.fr/wws/info/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

Reply via email to