I believe that you'll have no alternative but to inline your function, since it relies on the constraint that the type 'a has a method called get_Zero (this is inherited from the GenericZero function that you're using). Because there's normally no way to express this constraint in the .NET type system, your test method can't be translated into a normal function. Instead, the compiler will have to inline it everywhere it's used, finding and using the appropriate get_Zero method on the static type at the usage site.

Anyone please correct me if I'm wrong.

By on 2/23/2009 3:08 PM ()

What about for type definitions? I am attempting something like the following:

1
2
3
4
5
6
type FieldValue<'a when 'a : (static member Parse: string -> 'a)>(arg:string) =

    let value = 'a.Parse(arg) 

    member m.Value = value

The 1.9.6.16 compiler chokes on the following:

1
'a.Parse(arg)
By on 7/9/2009 1:21 PM ()

I think member constraints are only allowed with inlined let bound functions. The type variable must be statically resolved (^a), and you can't have that in a type itself.

I agree though, this would be really cool; something like typeclasses...

By on 7/9/2009 2:01 PM ()

Yeah,

just give us typeclasses.

And if you are on to it: just give us static interface members and extension properties as well ;)

By on 7/9/2009 9:18 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