Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
* Typing-problem
@ 1999-05-30 15:24 aXl
  1999-05-31 10:37 ` Typing-problem Jean-Christophe Filliatre
  1999-05-31 12:42 ` Typing-problem hubert.fauque
  0 siblings, 2 replies; 3+ messages in thread
From: aXl @ 1999-05-30 15:24 UTC (permalink / raw)
  To: caml-list

Hi, 
why is in the following example b of type "string -> string" ?

	let a = id id;;
	let b = a;;
	a "foo";; 
	(* until here it's covered by the faq's *)
	b;;

Thanks,
Axel Krauth 




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

* Re: Typing-problem
  1999-05-30 15:24 Typing-problem aXl
@ 1999-05-31 10:37 ` Jean-Christophe Filliatre
  1999-05-31 12:42 ` Typing-problem hubert.fauque
  1 sibling, 0 replies; 3+ messages in thread
From: Jean-Christophe Filliatre @ 1999-05-31 10:37 UTC (permalink / raw)
  To: aXl; +Cc: caml-list


> why is in the following example b of type "string -> string" ?
> 
> 	let a = id id;;
> 	let b = a;;
> 	a "foo";; 
> 	(* until here it's covered by the faq's *)
> 	b;;

It is because:

  1. the type variable is not generalized is the type of a;
     (it is '_a -> '_a)

  2. that type variable is shared between the types of a and b

Therefore when applying a to "foo", that type variable is instanciated
by string, which instanciates also the type of b.

A more detailed explanation is given here :

  http://caml.inria.fr/FAQ/FAQ_EXPERT-eng.html#polymorphisme

Best regards,
-- 
Jean-Christophe FILLIATRE
  mailto:Jean-Christophe.Filliatre@lri.fr
  http://www.lri.fr/~filliatr




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

* Re: Typing-problem
  1999-05-30 15:24 Typing-problem aXl
  1999-05-31 10:37 ` Typing-problem Jean-Christophe Filliatre
@ 1999-05-31 12:42 ` hubert.fauque
  1 sibling, 0 replies; 3+ messages in thread
From: hubert.fauque @ 1999-05-31 12:42 UTC (permalink / raw)
  To: caml-list

aXl <krauth@fmi.uni-passau.de> writes:

> Hi, 
> why is in the following example b of type "string -> string" ?

because a is of type string->string and b=a

> 
> 	let a = id id;;
> 	let b = a;;
> 	a "foo";; 
> 	(* until here it's covered by the faq's *)
> 	b;;

let b = a   defines a new name (b) for the object designed by a;
it doesn't construct a new object, and it doesn't do a new call (id id);

it is different from
let a = id id;;
let b = id id;;


The Caml let ..= ..  is different from the assignment in C or Pascal;
in C if you write
        a=b;
there is a variable "a" which already as a place
in memory, and a=b means: copy the memory location of b to a;

in Caml let defines a new name; it's the right of the = which may
construct a new object; that's why 
let a = id id
let b = a

is different from 
lat a = id id
let b = id id


Hubert
hubert.fauque@inria.fr




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

end of thread, other threads:[~1999-06-01 15:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-05-30 15:24 Typing-problem aXl
1999-05-31 10:37 ` Typing-problem Jean-Christophe Filliatre
1999-05-31 12:42 ` Typing-problem hubert.fauque

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