caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Pervasives.compare != Pervasives.compare
@ 2010-11-12  5:57 Elnatan Reisner
  2010-11-12 10:50 ` [Caml-list] " Stéphane Glondu
  0 siblings, 1 reply; 2+ messages in thread
From: Elnatan Reisner @ 2010-11-12  5:57 UTC (permalink / raw)
  To: OCaml List

I was surprised when I noticed the following behavior:

         Objective Caml version 3.11.2

# compare == compare;;
- : bool = false
# let f = compare;;
val f : 'a -> 'a -> int = <fun>
# f == compare;;
- : bool = false
# f == f;;
- : bool = true
# let g = compare;;
val g : 'a -> 'a -> int = <fun>
# f == g;;
- : bool = false

Playing around a bit more, I seemed to find that every time you access  
an 'external' function, you get a distinct reference (is there a  
better term?) to it. This seems a bit odd to me. Can someone explain?

Thanks,

Elnatan


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

* Re: [Caml-list] Pervasives.compare != Pervasives.compare
  2010-11-12  5:57 Pervasives.compare != Pervasives.compare Elnatan Reisner
@ 2010-11-12 10:50 ` Stéphane Glondu
  0 siblings, 0 replies; 2+ messages in thread
From: Stéphane Glondu @ 2010-11-12 10:50 UTC (permalink / raw)
  To: Elnatan Reisner; +Cc: caml-list

Le 12/11/2010 06:57, Elnatan Reisner a écrit :
> Playing around a bit more, I seemed to find that every time you access
> an 'external' function, you get a distinct reference (is there a better
> term?) to it. This seems a bit odd to me. Can someone explain?

Think of externals as constructors: they are always fully applied 
internally. So when you partially apply one (or use it with no 
arguments), the compiler eta-expands it and generates a closure that 
eats the remaining arguments and call the external.

You can use the -dinstr (in bytecode) or -S (in native code) 
command-line switch to see how things are actually compiled.


Cheers,

-- 
Stéphane


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

end of thread, other threads:[~2010-11-12 10:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-11-12  5:57 Pervasives.compare != Pervasives.compare Elnatan Reisner
2010-11-12 10:50 ` [Caml-list] " Stéphane Glondu

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