Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
* weird type behavior
@ 2006-10-28 15:49 Kirill
  2006-10-28 16:12 ` [Caml-list] " Richard Jones
  0 siblings, 1 reply; 7+ messages in thread
From: Kirill @ 2006-10-28 15:49 UTC (permalink / raw)
  To: caml-list

Hi everyone,

I'm a novice user of OCaml and functional languages in general. While
playing with the interpreter, writing all kinds of functions, I've run
into a behavior that doesn't look quite right to me. Please excuse me,
if it is explained somewhere and I simply haven't gotten there yet.

In the following example, I define a simple function foo that returns
function bar, which, in turn, accepts 2 parameters. The weird part is
that after bar is being called for the first time, its signature changes
from polymorphic types to ints. Right after (foo 3) call it's
  '_a -> '_b -> '_b = <fun>
But after being called, it becomes
  (int -> int) -> int -> int = <fun>


# let foo n =
    let bar f x = x in bar;;
val foo : 'a -> 'b -> 'c -> 'c = <fun>

# let inc x = x + 1;;
val inc : int -> int = <fun>

# let z = foo 3;;
val z : '_a -> '_b -> '_b = <fun>

# z inc 0;;
- : int = 0
# z;;
- : (int -> int) -> int -> int = <fun>


I have also noticed that if foo doesn't accept parameters, everything
works as expected:

# let foo =
    let bar f x = x in bar;;
val foo : 'a -> 'b -> 'b = <fun>
# let inc x = x + 1;;
val inc : int -> int = <fun>
# let z = foo;;
val z : 'a -> 'b -> 'b = <fun>
# z inc 0;;
- : int = 0
# z;;
- : 'a -> 'b -> 'b = <fun>

I have tried this with 3.09.2 and 3.09.3 on X64 Ubuntu.

I have also noticed other things I don't see explanation for, but they
may be connected to this one. Will be grateful for any explanation. 

Thanks,
-Kirill


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

end of thread, other threads:[~2006-10-30  8:06 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-10-28 15:49 weird type behavior Kirill
2006-10-28 16:12 ` [Caml-list] " Richard Jones
2006-10-28 17:17   ` Kirill
     [not found]   ` <20061028161506.GA2596@furbychan.cocan.org>
     [not found]     ` <1162083950.23148.58.camel@nfnl>
2006-10-29  1:12       ` Kirill
2006-10-29  1:34         ` Kirill
2006-10-29  5:07         ` skaller
2006-10-29 10:03   ` Boris Yakobowski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox