Yes, that's right, you can't overload comparison operators, except by implementing IComparable.

How about defining your own set of operators that you reserve to correspond to constructions. e.g. you could systematically use the "+." etc. operators that OCaml uses for floating point addition (these don't tend to get used in F# since + etc. are overloaded).

1
2
let inline (+.) x y = (^a: (static member (+.) : ^a * ^b -> ^c) (x,y))
let inline (<.) x y = (^a: (static member (<.) : ^a * ^b -> ^c) (x,y))

and then implementing these on your types.

Don

By on 10/10/2006 1:43 PM ()

Thanks, that makes sense. I currently have a bunch of global operators using a colon as the differentiating character; (+:), (-:) etc. Rather than use the "inline static member" syntax you give above they are just global ocaml style declarations:

1
let (+:) a b = ....

I noticed then when I build a new class and used these operators within it the top level delcarations got in the way. So perhaps if I mark these operators for proper overloading then I'll be abe to define new types which build on the basic ones i.e. to give implementations for Signed/Unsigned arithmetic, Fixed point arithmetic and so on.

Cheers,

Andy

By on 10/11/2006 3:26 AM ()

I noticed then when I build a new class and used these operators within it the top level delcarations got in the way. So perhaps if I mark these operators for proper overloading then I'll be abe to define new types which build on the basic ones i.e. to give implementations for Signed/Unsigned arithmetic, Fixed point arithmetic and so on.

Yes, that's right - overloaded operators need "let (+.) x y = ..." bindings that show how they map through to members on particular types. For example, the (.[]) operator maps across to a requirement that an "Item" property exist on the type of the value being accessed.

Cheers!

Don

By on 10/14/2006 9:34 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