1 people like it.

Why automatic upcasting would not work

N/A

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
14: 
15: 
16: 
17: 
18: 
19: 
// Consider two distinct interfaces
type IA = interface end
type IB = interface end

// And two classes that implement both of the interfaces
type First() = 
  interface IA
  interface IB

type Second() = 
  interface IA
  interface IB

// Now, what implicit upcast should the compiler insert here?
// The return type could be either IA, IB or obj, but there is 
// no _unique_ solution.
let test = 
  if 1 = 1 then First()
  else Second()
type IB

Full name: Script.IB
Multiple items
type First =
  interface IB
  interface IA
  new : unit -> First

Full name: Script.First

--------------------
new : unit -> First
type IA

Full name: Script.IA
Multiple items
type Second =
  interface IB
  interface IA
  new : unit -> Second

Full name: Script.Second

--------------------
new : unit -> Second
val test : First

Full name: Script.test
Next Version Raw view Test code New version

More information

Link:http://fssnip.net/ix
Posted:10 years ago
Author:
Tags: na