caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* evaluation order ...
@ 2006-07-11  7:55 Pietro Abate
  2006-07-11  8:42 ` [Caml-list] " Richard Jones
  0 siblings, 1 reply; 2+ messages in thread
From: Pietro Abate @ 2006-07-11  7:55 UTC (permalink / raw)
  To: ocaml ml

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


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

* Re: [Caml-list] evaluation order ...
  2006-07-11  7:55 evaluation order Pietro Abate
@ 2006-07-11  8:42 ` Richard Jones
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Jones @ 2006-07-11  8:42 UTC (permalink / raw)
  To: Pietro Abate, ocaml ml

On Tue, Jul 11, 2006 at 05:55:19PM +1000, Pietro Abate wrote:
> 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 ?

'_a isn't the same as 'a

There is a FAQ on this:

http://caml.inria.fr/pub/old_caml_site/FAQ/FAQ_EXPERT-eng.html#variables_de_types_faibles

Rich.

-- 
Richard Jones, CTO Merjis Ltd.
Merjis - web marketing and technology - http://merjis.com
Team Notepad - intranets and extranets for business - http://team-notepad.com


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

end of thread, other threads:[~2006-07-11  8:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-07-11  7:55 evaluation order Pietro Abate
2006-07-11  8:42 ` [Caml-list] " Richard Jones

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