Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Ml > Re: Warning: ty...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 1 Topic 919 of 968
Post > Topic >>

Re: Warning: type vars not generalized because of, value restriction

by torbenm@[EMAIL PROTECTED] (Torben Ęgidius Mogensen) Aug 21, 2007 at 02:47 PM

JT <jt@[EMAIL PROTECTED]
> writes:

> Chris Reade escreveu:

>> fun f1 (x,y,z) = (x,y,1)
>> fun f2 (x,y,z) = (x,y,z * x)
>> fun f3 (x, y,z) = (x + 1, y, z)
>> val body = f3 o f2

> Upon evaluating this, an error crops up.
>
> - val body = f3 o f2;
> stdIn:5.5-5.19 Warning: type vars not generalized because of
>     value restriction are instantiated to dummy types (X1,X2,...)
> val body = fn : int * ?.X1 * int -> int * ?.X1 * int
>
> This must have something to do with the newer SML 97 standard.

It does indeed.  SML 97 restricts non-values in val bindings to
monomorphic to avoid problems with polymorphic references.  Since the
expression f3 o f2 is not a value, it is not generalized (made
polymorphic).  To get around the problem, you can eta-expand the
expression:

  val body = fn arg => (f3 o f2) arg

which reduces to

  val body = fn arg => f3 (f2 arg)

or, even simpler,

  fun body arg = f3 (f2 arg)

	Torben
 




 1 Posts in Topic:
Re: Warning: type vars not generalized because of, value restric
torbenm@[EMAIL PROTECTED]  2007-08-21 14:47:22 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Jul 25 0:19:28 CDT 2008.