Re : [Caml-list] Warning wished
> Hello, > > Is it a bug or a well-known feature that the above program does not emit > a warning (because "f x" should have type unit in the body of "g") ? > > = > let f x = x > let g x = f x; 1 > (* let _ = g 2 *) > I'm not familiar with the internals of the compiler, but what I suppose is happening is that it tries to unify the type of "f x" and "unit", and this succeeds because "f x" has type 'a, which can be unified with anything. The meaning of "a;b" seems to be let _ = a in b rather than let () = a in b. But like I said, these are suppositions. Cheers, Matthieu > > Best regards, > Julien Signoles > > ___ > Caml-list mailing list. Subscription management: > http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list > Archives: http://caml.inria.fr > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs ___ Caml-list mailing list. Subscription management: http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list Archives: http://caml.inria.fr Beginner's list: http://groups.yahoo.com/group/ocaml_beginners Bug reports: http://caml.inria.fr/bin/caml-bugs
Re: [Caml-list] Warning wished
Hello Julien, no warning should be issued in this case since you have polymorphic function: applying g to () you will definitely have f x of type unit :) Try another one: let f x = x+1 let g x = f x; 1 Now you'll get the warning since the compiler can ensure that type of f x can never be unit. Best regards, Dmitry. Hello, Is it a bug or a well-known feature that the above program does not emit a warning (because "f x" should have type unit in the body of "g") ? = let f x = x let g x = f x; 1 (* let _ = g 2 *) Best regards, Julien Signoles ___ Caml-list mailing list. Subscription management: http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list Archives: http://caml.inria.fr Beginner's list: http://groups.yahoo.com/group/ocaml_beginners Bug reports: http://caml.inria.fr/bin/caml-bugs ___ Caml-list mailing list. Subscription management: http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list Archives: http://caml.inria.fr Beginner's list: http://groups.yahoo.com/group/ocaml_beginners Bug reports: http://caml.inria.fr/bin/caml-bugs
Re: [Caml-list] Warning wished
Hello Dmitri, > no warning should be issued in this case since you have polymorphic > function: > applying g to () you will definitely have f x of type unit :) Applying g to 1 you will definitely have f x of type int and you have to take care of the returned integer. Unfortunatly caml emits no warning in this case (even if I understand why) :(. -- Julien ___ Caml-list mailing list. Subscription management: http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list Archives: http://caml.inria.fr Beginner's list: http://groups.yahoo.com/group/ocaml_beginners Bug reports: http://caml.inria.fr/bin/caml-bugs
Re: [Caml-list] Warning wished
Applying g to 1 you will definitely have f x of type int and you have to take care of the returned integer. Unfortunatly caml emits no warning in this case (even if I understand why) :(. Sure :) But as far as I understand this warning means "this non-unit value will definitely be omitted, and this can be possibly wrong". Under this interpretation the compiler has to ensure undoubtedly that the value is always non-unit. BTW you may (temporarily) change your code into something like let f x = [x] of even into let f x = object method get = x end and find all the suspicious places :) Best regards, Dmitri. ___ Caml-list mailing list. Subscription management: http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list Archives: http://caml.inria.fr Beginner's list: http://groups.yahoo.com/group/ocaml_beginners Bug reports: http://caml.inria.fr/bin/caml-bugs
Re: [Caml-list] Warning wished
Julien SIGNOLES wrote: > Hello, > > Is it a bug or a well-known feature that the above program does not emit > a warning (because "f x" should have type unit in the body of "g") ? > > = > let f x = x > let g x = f x; 1 > (* let _ = g 2 *) > The compiler could have a command-line switch that enforces the unit type in sequences, i.e. it would add type annotations for you: let f x = x let g x = (f x : unit); 1 There's a camlp4/camlp5 syntax extension that does this (but I don't use it). Martin -- http://mjambon.com/ ___ Caml-list mailing list. Subscription management: http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list Archives: http://caml.inria.fr Beginner's list: http://groups.yahoo.com/group/ocaml_beginners Bug reports: http://caml.inria.fr/bin/caml-bugs
Re: [Caml-list] Warning wished
Dmitri Boulytchev wrote: Applying g to 1 you will definitely have f x of type int and you have to take care of the returned integer. Unfortunatly caml emits no warning in this case (even if I understand why) :(. Sure :) But as far as I understand this warning means "this non-unit value will definitely be omitted, and this can be possibly wrong". Under this interpretation the compiler has to ensure undoubtedly that the value is always non-unit. BTW you may (temporarily) change your code into something like let f x = [x] of even into let f x = object method get = x end and find all the suspicious places :) Best regards, Dmitri. There's the question of what the compiler _does_, what the compiler _could_ do and what the compiler _should_ do. I don't think "this 'a could be unit" is a good reason for skipping the warning. On the contrary, "this 'a will probably sometimes be a real value" seems a sufficient reason to add a warning. If needed, the programmer can easily suppress the warning by adding "ignore" or adding a ": unit" type constraint (whichever applies). (Remains to see whether adding the warning to OCaml is worth the manwork.) Frédéric ___ Caml-list mailing list. Subscription management: http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list Archives: http://caml.inria.fr Beginner's list: http://groups.yahoo.com/group/ocaml_beginners Bug reports: http://caml.inria.fr/bin/caml-bugs
Re: [Caml-list] Warning wished
There's the question of what the compiler _does_, what the compiler _could_ do and what the compiler _should_ do. The latter is mainly a matter of taste :) I don't think "this 'a could be unit" is a good reason for skipping the warning. On the contrary, "this 'a will probably sometimes be a real value" seems a sufficient reason to add a warning. If needed, the programmer can easily suppress the warning by adding "ignore" or adding a ": unit" type constraint (whichever applies). I believe that compiler for statically-typed languages has to take all the responsibility on type information it delivers to user. So when it says "this expression has type X, but here is used as type unit" it must not mean "well, sometimes it hasn't" :) (Remains to see whether adding the warning to OCaml is worth the manwork.) IMHO it definitely doesn't deserve such a long discussion : BR, Dmitri. ___ Caml-list mailing list. Subscription management: http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list Archives: http://caml.inria.fr Beginner's list: http://groups.yahoo.com/group/ocaml_beginners Bug reports: http://caml.inria.fr/bin/caml-bugs
Re: Re : [Caml-list] Warning wished
Le mercredi 28 janvier 2009 à 14:07 +, Matthieu Wipliez a écrit : > > Hello, > > > > Is it a bug or a well-known feature that the above program does not emit > > a warning (because "f x" should have type unit in the body of "g") ? > > > > = > > let f x = x > > let g x = f x; 1 > > (* let _ = g 2 *) > > > > I'm not familiar with the internals of the compiler, but what I suppose is > happening is that it tries to unify the type of "f x" and "unit", and this > succeeds because "f x" has type 'a, which can be unified with anything. The > meaning of "a;b" seems to be let _ = a in b rather than let () = a in b. > > But like I said, these are suppositions. Sure. However in my real case, I had an "ok" code like this : let f x : 'a -> unit = ... let g x = f x; x I changed a little bit the specification of f : let f x : 'a -> 'a = ... I just expected that caml helps me to find all the instances where I had to take care of this specification change. Such a thing is one of the very good features of caml. Unfortunatly, in this case, caml did not help me while the old implementation of "g" became wrong with the new specification of "f" :-(. -- Julien ___ Caml-list mailing list. Subscription management: http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list Archives: http://caml.inria.fr Beginner's list: http://groups.yahoo.com/group/ocaml_beginners Bug reports: http://caml.inria.fr/bin/caml-bugs
Re: Re : [Caml-list] Warning wished
Excerpts from Julien SIGNOLES's message of Wed Jan 28 15:24:14 +0100 2009: > Le mercredi 28 janvier 2009 à 14:07 +, Matthieu Wipliez a écrit : > > > Hello, > > > > > > Is it a bug or a well-known feature that the above program does not emit > > > a warning (because "f x" should have type unit in the body of "g") ? > > > > > > = > > > let f x = x > > > let g x = f x; 1 > > > (* let _ = g 2 *) > > > > > > > I'm not familiar with the internals of the compiler, but what I suppose is > > happening is that it tries to unify the type of "f x" and "unit", and this > > succeeds because "f x" has type 'a, which can be unified with anything. The > > meaning of "a;b" seems to be let _ = a in b rather than let () = a in b. > > > > But like I said, these are suppositions. > > Sure. However in my real case, I had an "ok" code like this : > > let f x : 'a -> unit = ... > let g x = > f x; > x > > I changed a little bit the specification of f : > > let f x : 'a -> 'a = ... > > I just expected that caml helps me to find all the instances where I had > to take care of this specification change. Such a thing is one of the > very good features of caml. Unfortunatly, in this case, caml did not > help me while the old implementation of "g" became wrong with the new > specification of "f" :-(. That's because (let f x : 'a -> 'a = ...) is not a specification for a polymorphic function, this is rather an existential quantification than a universal one. They are some ugly tricks to ensure a polymorphic function, like this one: module M : sig val f : t -> 'a -> 'a end = struct let f x = ... end include M Best regards, -- Nicolas Pouillard ___ Caml-list mailing list. Subscription management: http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list Archives: http://caml.inria.fr Beginner's list: http://groups.yahoo.com/group/ocaml_beginners Bug reports: http://caml.inria.fr/bin/caml-bugs