Not sure. Maybe because the type of the value you're passing in as 'a (Factory.Singleton?) is sealed? Try leaving off the the type annotations completely, or reproducing using an independent example.

By on 5/25/2009 9:18 AM ()

Well if I try only this

1
2
3
4
5
    member private x.EmptyArray
        with get():InjectionMember[] =  Array.create 0 (Unchecked.defaultof<InjectionMember>)
        
    member private x.Register<'a, 'b when 'b :> 'a> (container:IUnityContainer):unit =
        container.RegisterType<'a, 'b>(x.EmptyArray) |> ignore

I still get

Error 1 invaid constraint: the type used for the constraint is sealed, which means the constraint could only be satisfied by at most one solution.

I think by sealed the compiler means that the constraint is sealed not the types being passed. Also when I double click on the error it highlights that part when 'b :> 'a

When I mouse hover container.RegisterType I got this:

1
2
3
IUnityContainer.RegisterType<'TFrom,'TTo (requires 'TTo :>

'TFrom)>(InjectionMember array injectionMembers):IUnityContainer

May be that would help you find out what's the issue?

By on 5/25/2009 9:35 AM ()

This is the answer to similar question I found here:

[link:article.gmane.org]

This is a restriction imposed to make F# type inference tractable. In particular, the type on the right of a
subtype constraint must be nominal. Note constraints of the form “'a :> 'b” are always eagerly solved
to 'a = 'b, as specified in section 14.6 of the F# specification.

There are occasional use cases for static constraints of the form below, typically in forms of OO
programming making extensive use of hierarchical encodings, which are rarely used in F# and not
particularly encouraged. That said, it is possible a future version of F# (not V1) will permit the
declaration of these constraints, as long as individual instantiations give a nominal type for 'b.

Does it mean I can't use that in the current implementation of F#?

By on 5/25/2009 9:43 AM ()

Pretty sure you got it there. I'd suggest emailing fsbugs to let them know this is important to you. I ran into a similar problem (I think) the other day.

By on 5/25/2009 10:31 AM ()
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