This site is updated infrequently. For up-to-date information, please visit the new OCaml website at ocaml.org.

evaluation order ...
• Pietro Abate
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
 Date: 2006-07-11 (07:55) From: Pietro Abate Subject: evaluation order ...
```Hi all,

#type ('a,'w) mt = ('a -> 'w) -> 'w
#let return a = fun k -> k a ;;
#let a = return 4 ;;
type ('a, 'b) mt = ('a -> 'b) -> 'b
val return : 'a -> ('a -> 'b) -> 'b = <fun>
val a : (int -> '_a) -> '_a = <fun>
#

# let b = a print_int;;
4val b : unit = ()

as expected ... but

# let c = a id;;
This expression has type int -> int but is here used with type int -> unit

if I invert the order ...

#let a = return 4 ;;
val a : (int -> '_a) -> '_a = <fun>
#let c = a id;;;;
val c : int = 4
#let b = a print_int;;
This expression has type int -> unit but is here used with type int -> int
#

why does the order matter ?
if "val a" is of type (int -> '_a) -> '_a = <fun> why '_a is fixed as soon
as I use it once ? Do I have to add a type constraint ?

:)
p

--
++ Blog: http://blog.rsise.anu.edu.au/?q=pietro
++
++ "All great truths begin as blasphemies." -George Bernard Shaw
++ Please avoid sending me Word or PowerPoint attachments.
See http://www.fsf.org/philosophy/no-word-attachments.html

```