Only inline functions can use ^T. You can't use it as a generic class/struct type parameter.

By on 11/28/2010 9:01 PM ()

Only inline functions can use ^T. You can't use it as a generic class/struct type parameter.

Actually, this isn't quite true:

1
2
3
4
5
6
type TyWithZero< ^T when ^T : (static member Zero : ^T)>() =
  member inline x.ZeroElement : ^T = LanguagePrimitives.GenericZero


let z = TyWithZero<int>().ZeroElement
let oops = TyWithZero<string>()  // won't compile; string has no static Zero member

However, since it's impossible to mark a constructor as inline the original code can't easily be made to work.

By on 11/29/2010 9:16 AM ()

Thank you for your answer.
Just to be sure...it's not possible to create a generic class/struct that would use arithmetic on the associated type (float, int, custom type,...) ?

By on 11/29/2010 3:46 AM ()

I'm working on it. By now you can use not very beautiful library. See a thread in General Discussion about type classes.
Library can be found here.

By on 11/29/2010 11:00 AM ()

Thank you :)

By on 1/11/2011 3:12 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