开发者

F# -> Generic type - Multiple not struct

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 '>' 开发者_StackOverflow社区or other token.

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

UPDATE:

My full code is:

type ManyNavigationPropertyInfo<'a,'b>(cfg:ManyNavigationPropertyConfiguration<'a, 'b>) =
    member x.WithMany (expr: Expr<'a -> ICollection<'b>>) = 
        cfg.WithMany(ToLinq(expr))

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


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.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜