Take the 2-minute tour ×

My first thought was:

type ManyNavigationPropertyInfo<'a,'b>(cfg:ManyNavigationPropertyConfiguration<'a, 'b>) =

however it resolves 'a and 'b as obj, but it should be classes - therefore I did:

type ManyNavigationPropertyInfo<'a when 'a : not struct,'b when 'b : not struct>(cfg:ManyNavigationPropertyConfiguration<'a, 'b>) =

but that just throws an error saying

Unexpected symbol ',' in type name. Expected '>' or other token.

What's the correct way for declaring such a type?


My full code is:

    member x.WithMany (expr: Expr<'a -> ICollection<'b>>) = 

and it comes up with 2 compiler errors saying that 'a and 'b should be not struct.

share|improve this question

1 Answer 1

up vote 3 down vote accepted

Your first thought is correct. You should be able to just write:

type ManyNavigationPropertyInfo<'a,'b>
       (cfg:ManyNavigationPropertyConfiguration<'a, 'b>) =
   // ...

The problem is probably somewhere later in the body of the type. From something that you wrote in the body, the compiler thinks that 'a and 'b must be of type obj (e.g. you're passing values of this type somewhere where obj is expected, or probably something more subtle).

You can try adding type annotations in the body of the class - this usually helps to find the issue, because the error message changes when you annotate the bit that F# compiler interprets differently than you expected.

To solve the immediate problem in your question - the syntax for specifying constraint is a bit different (first write all type variables and then constraints):

type ManyNavigationPropertyInfo<'a, 'b when 'a : not struct and 'b : not struct>( ... )

(But if you can post larger portion of code, maybe somebody can give a concrete advice.)

share|improve this answer

Your Answer


