Does F# support some kind of dependent type? If not, I can't see a clear answer.

By on 11/8/2007 12:53 AM ()

Good question!

You ought to be able to write

1
let f (c : C<'a>) (a : 'b) : int when 'a :> Base and 'b :> 'a = c.c.a + a.a

but for whatever reason F# decides to unify 'a and 'b which is not what we want. So we could try making the type variables rigid like so

1
let f<'a, 'b when 'a :> Base and 'b :> 'a> (c : C<'a>) (a : 'b) : int = c.c.a + a.a

But this produces many interesting compiler errors. It would seem that the compiler is treating 'a in the constraint 'b :> 'a as a sealed type, which is not really correct, and concluding that the constaint is invalid. My guess is that this is a compiler bug.

By on 11/7/2007 8:22 PM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper