caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Re: [Caml-list] Weird typing problem
@ 2002-05-21 23:48 Ryan Tarpine
  0 siblings, 0 replies; 6+ messages in thread
From: Ryan Tarpine @ 2002-05-21 23:48 UTC (permalink / raw)
  To: caml-list

>From: Ching-Tsun Chou To: pixel@mandrakesoft.com CC: 
>caml-list@pauillac.inria.fr Subject: Re: [Caml-list] Weird typing problem 
>Date: Tue, 21 May 2002 16:20:11 -0700 (PDT)
>
>Thanks! But I still fail to see why the compiler and the interpreter should 
>behave differently.
>
>- Ching Tsun

Being only a beginner, I think it's because in the interpreter the type of 
the function doesn't need to be "finalized" completely, while in the 
compiler must *absolutely* have the exact type so it can generate code.  In 
the interpreter, it's fine for the type to be "refined" later on, because it 
won't be accessed by any outside applications.

The compiler can't generate code for functions with arguments of type '_a 
because that would require the object code to be modified when the function 
is called for the first time.  The code would need to be changed depending 
on which program called it, since (list_last [2;3]) and (list_last 
[2.0;3.0]) would have different effects (the first one would make the type 
of list_last be ints to ints while the second floats to floats).

HTH,

Ryan Tarpine, rtarpine@hotmail.com
"To err is human, to compute divine. Trust your computer but not its 
programmer."
- Morris Kingston

_________________________________________________________________
MSN Photos is the easiest way to share and print your photos: 
http://photos.msn.com/support/worldwide.aspx

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

* Re: [Caml-list] Weird typing problem
@ 2002-05-22  0:14 Ryan Tarpine
  0 siblings, 0 replies; 6+ messages in thread
From: Ryan Tarpine @ 2002-05-22  0:14 UTC (permalink / raw)
  To: ctchou, caml-list

>From: Ching-Tsun Chou <ctchou@mipos2.intel.com>
>To: caml-list@inria.fr
>Subject: Re: [Caml-list] Weird typing problem
>Date: Tue, 21 May 2002 16:58:32 -0700 (PDT)
>
>Why can't the compiler just substitute 'a for '_a if '_a can't be
>resolved?  What's wrong with that?  Surely O'Caml can handle
>polymorphism.
>
>- Ching Tsun
>-------------------

See http://caml.inria.fr/FAQ/FAQ_EXPERT-eng.html#polymorphisme.  In short, 
(quoted from the FAQ)

When type-checking
  let name = expr1 ...
The type of expr1 is generalized when expr1 is a function, an dentifier or a 
constant. Otherwise the identifier name is not polymorphic (type variables 
are not generalized).
...
The new rule implies that if expr1 is a function application, then the 
identifier name is monomorphic

This is done because "a secure type system for Caml must forbid the 
existence of polymorphic mutable values at run-time" and this was basically 
the easiest way to do it.  Read the FAQ for an example.

HTH,

Ryan Tarpine, rtarpine@hotmail.com
"To err is human, to compute divine.  Trust your computer but not its 
programmer."
  - Morris Kingston


_________________________________________________________________
Send and receive Hotmail on your mobile device: http://mobile.msn.com

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

* Re: [Caml-list] Weird typing problem
       [not found] <F143h1mIs1Dk3fqSUVd000021b5@hotmail.com>
@ 2002-05-21 23:58 ` Ching-Tsun Chou
  0 siblings, 0 replies; 6+ messages in thread
From: Ching-Tsun Chou @ 2002-05-21 23:58 UTC (permalink / raw)
  To: caml-list


   Being only a beginner, I think it's because in the interpreter the type of 
   the function doesn't need to be "finalized" completely, while in the 
   compiler must *absolutely* have the exact type so it can generate code.  In 
   the interpreter, it's fine for the type to be "refined" later on, because it 
   won't be accessed by any outside applications.

   The compiler can't generate code for functions with arguments of type '_a 
   because that would require the object code to be modified when the function 
   is called for the first time.  The code would need to be changed depending 
   on which program called it, since (list_last [2;3]) and (list_last 
   [2.0;3.0]) would have different effects (the first one would make the type 
   of list_last be ints to ints while the second floats to floats).

Why can't the compiler just substitute 'a for '_a if '_a can't be
resolved?  What's wrong with that?  Surely O'Caml can handle
polymorphism.

- Ching Tsun
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

* Re: [Caml-list] Weird typing problem
  2002-05-21 23:03 ` Pixel
@ 2002-05-21 23:20   ` Ching-Tsun Chou
  0 siblings, 0 replies; 6+ messages in thread
From: Ching-Tsun Chou @ 2002-05-21 23:20 UTC (permalink / raw)
  To: pixel; +Cc: caml-list


Thanks!  But I still fail to see why the compiler and the interpreter
should behave differently.

- Ching Tsun

   X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f
   Cc: caml-list@pauillac.inria.fr
   From: Pixel <pixel@mandrakesoft.com>
   Date: 22 May 2002 01:03:59 +0200
   User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2
   Content-Type: text/plain; charset=us-ascii
   Sender: owner-caml-list@pauillac.inria.fr
   Precedence: bulk

   Ching-Tsun Chou <ctchou@mipos2.intel.com> writes:

   [...]

   > let list_last = List.hd << List.rev

   [...]

   > val list_last : '_a list -> '_a = <fun>

   make it:


   let list_last l = (List.hd << List.rev) l

   val list_last : 'a list -> 'a


   that's monomorphism restriction:
   http://caml.inria.fr/FAQ/FAQ_EXPERT-eng.html#variables_de_types_faibles
   -------------------
   To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
   Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
   Beginner's list: http://groups.yahoo.com/group/ocaml_beginners

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

* Re: [Caml-list] Weird typing problem
  2002-05-21 22:13 Ching-Tsun Chou
@ 2002-05-21 23:03 ` Pixel
  2002-05-21 23:20   ` Ching-Tsun Chou
  0 siblings, 1 reply; 6+ messages in thread
From: Pixel @ 2002-05-21 23:03 UTC (permalink / raw)
  To: Ching-Tsun Chou; +Cc: caml-list

Ching-Tsun Chou <ctchou@mipos2.intel.com> writes:

[...]

> let list_last = List.hd << List.rev

[...]

> val list_last : '_a list -> '_a = <fun>

make it:


let list_last l = (List.hd << List.rev) l

val list_last : 'a list -> 'a


that's monomorphism restriction:
http://caml.inria.fr/FAQ/FAQ_EXPERT-eng.html#variables_de_types_faibles
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

* [Caml-list] Weird typing problem
@ 2002-05-21 22:13 Ching-Tsun Chou
  2002-05-21 23:03 ` Pixel
  0 siblings, 1 reply; 6+ messages in thread
From: Ching-Tsun Chou @ 2002-05-21 22:13 UTC (permalink / raw)
  To: caml-list


Consider a file "zzz.ml" that contains only two lines:

let (<<) f g x = f (g (x))
let list_last = List.hd << List.rev

Now, if I load the file interactively, I get:

<unix> ocaml
        Objective Caml version 3.04

# #use "zzz.ml" ;;
val ( << ) : ('a -> 'b) -> ('c -> 'a) -> 'c -> 'b = <fun>
val list_last : '_a list -> '_a = <fun>
# 

However, if I try to compile it, I get:

<unix> ocamlc -c zzz.ml
File "zzz.ml", line 2, characters 16-35:
The type of this expression, '_a list -> '_a,
contains type variables that cannot be generalized


Why so?

- Ching Tsun
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

end of thread, other threads:[~2002-05-22  0:14 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-05-21 23:48 [Caml-list] Weird typing problem Ryan Tarpine
  -- strict thread matches above, loose matches on Subject: below --
2002-05-22  0:14 Ryan Tarpine
     [not found] <F143h1mIs1Dk3fqSUVd000021b5@hotmail.com>
2002-05-21 23:58 ` Ching-Tsun Chou
2002-05-21 22:13 Ching-Tsun Chou
2002-05-21 23:03 ` Pixel
2002-05-21 23:20   ` Ching-Tsun Chou

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).