[Grace-core] Types of blocks

Kim Bruce kim at cs.pomona.edu
Tue Aug 23 17:49:49 PDT 2011


These results make sense to me and I'd expect the same results in Grace.  If we added union types to Grace then we could use the union of the result types as the answer, which would give a more exact typing.  Note that this is really a matter of how we type an "if" statement not a block.  If's and matches are where these would show up.

Kim



On Aug 23, 2011, at 4:59 PM, James Noble wrote:

> So I typed versions of these at Scala: 
> 
> basically those that worked all go to Any (their top type)
> 
>> { (a : String, b : Boolean, c : Boolean) => if (b) { a } else { a.size } }
>> res5: (String, Boolean, Boolean) => Any = <function3>
>> 
>> { (a : String, b : Boolean, c : Boolean) => if (c) { return a } else if (b)  { a } else { a.size } }
>> could't get this one to work - return has to be in a method, and then scala says:
>> <console>:5: error: method foo has return statement; needs result type
>> 
>> the very similar is the same as the first case:
>> { (a : String, b : Boolean, c : Boolean) => if (c) { a } else if (b) { a } else { a.size } }
>> res7: (String, Boolean, Boolean) => Any = <function3>
>> 
>> (a : String, b : Boolean, c : Boolean) => if (c) { var b1 = c } else {if (b)  { a } else { a.size }}
>> res9: (String, Boolean, Boolean) => Any
> 
> J



More information about the Grace-core mailing list