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 > simple type inf...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 6 Topic 902 of 973
Post > Topic >>

simple type inference question(exercise from the Ullman book)

by sail0r <sail0r@[EMAIL PROTECTED] > Jul 4, 2007 at 02:06 AM

This is questions 3.2.3 (f) from Ullman's Elements book.
The questions is to figure out what the types of b,c,d,e are
for the following function
fun f(a:int,b,c,d,e)=
    if b<c then d else e

My answer is that b and c must be of the same type(< operator). Also d 
and e must be of the same type since the then and else branches of an if 
must have the same type. a is not used but is known to be of type int. 
Other than that we cannot further tell which are the types of b,c,d,e.

Now, Running the code in the sml interpreter, however, shows that
b and c are of type int.
val f = fn : int * int * int * 'a * 'a -> 'a
How is it that the int type is inferred for b and c?
 




 6 Posts in Topic:
simple type inference question(exercise from the Ullman book)
sail0r <sail0r@[EMAIL   2007-07-04 02:06:23 
Re: simple type inference question(exercise from the Ullman book
"Albert Y. C. Lai&qu  2007-07-05 17:56:57 
Re: simple type inference question(exercise from the Ullman book
cane <xxx@[EMAIL PROTE  2007-07-05 17:56:30 
Re: simple type inference question(exercise from the Ullman book
heiner.marxen@[EMAIL PROT  2007-07-05 17:56:44 
Re: simple type inference question(exercise from the Ullman book
Marc Olschok <nobody@[  2007-07-05 17:57:05 
Re: simple type inference question(exercise from the Ullman book
sail0r <sail0r@[EMAIL   2007-07-11 21:15:03 

Post A Reply:
  Go here to Signup

AddThis Feed Button


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

Contact
tan12V112 Sat Sep 6 23:11:41 CDT 2008.