Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Odd Type Checking Problem
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Tom Hirschowitz <Tom.Hirschowitz@i...>
Subject: Re: [Caml-list] Odd Type Checking Problem

Ok it is something else, just that the expression

let mAny = fun succ0 input -> succ0 in
let x = mAny (mAny true) in
mAny

is expansive and therefore cannot be generalized in, say

let h = 
  let mAny = fun succ0 input -> succ0 in
  let x = mAny (mAny true) in
  mAny
in ...

Tom Hirschowitz writes:
 > 
 > What about these ones :
 > 
 > # let mAny = fun succ0 input -> succ0 in
 >   let x = mAny (mAny true) in
 >   mAny;;
 > - : '_a -> '_b -> '_a = <fun>
 > 
 > # let mAny = fun succ0 input -> succ0 in
 >   mAny;;
 > - : 'a -> 'b -> 'a = <fun>
 > 
 > 
 > Alain Frisch writes:
 >  > On Wed, 6 Feb 2002, Jonathan D Eddy wrote:
 >  > 
 >  > > (* type checks *)
 >  > > let mAny = fun succ0 input -> succ0 in
 >  > >     let ans0 = true in
 >  > >     let x = mAny (mAny ans0) in
 >  > >         x 1 2
 >  > >
 >  > > (* does not type check *)
 >  > > let mAny: 'a -> int -> 'a = fun succ0 input -> succ0 in
 >  > >     let ans0 = true in
 >  > >     let x = mAny (mAny ans0) in
 >  > >         x 1 2
 >  > 
 >  > I guess this is a problem of understanding type variable scoping rules.
 >  > The scope of the 'a variable above is all the phrase, including
 >  > the (mAny (mAny ans0)). So the type annotation makes mAny monomorphic,
 >  > but you want to use it with two different types.
 >  > 
 >  > It seems that explicitly introduced type variables are generalized only
 >  > at the (syntactic) level above their introduction; this together with
 >  > unclear scoping rules may be confusing ...
 >  > 
 >  > 
 >  > -- Alain
 >  > 
 >  > -------------------
 >  > Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
 >  > To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr
 >  > 
 > -------------------
 > Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
 > To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr
 > 
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr