views:

179

answers:

1

I've read the blurb at StrangeLights, I've read the passage from Expert F# (page 119), but I can't see how they apply to my code:

For my tests, I want to check equality between floats, with a bit of tolerance. I'm converting everything to units of measure, but I want to be able to be 'generic':

let toleq (e:float<_>) a b = (abs ( a - b ) ) < e

I can then use this to check equality on different 'types' of float, or curry it to make a custom one:

toleqm = toleq 1.0e-10<m>

But I get the following message:

Type inference has inferred the signature
    val toleq : float<'u> -> float<'u> -> float<'u> -> bool
Either define 'toleq' as a simple data term, make it a function, or add a 
    type constraint to instantiate the type parameters.

I don't see how I can do any more to make it a function - I can't see any implicit parameters.

What's up?

+1  A: 

Well, I messed around a bit and found the solution, in desperation, but I'm not sure that I understand why...

let toleq (e:float<_>) (a:float<_>) (b:float<_>) = (abs ( a - b ) ) < e

Ugh, it's almost as ugly as generic declarations in C#.

Benjol