To be clear, this works fine:

1
2
3
4
5
6
7
8
 

[<Measure>] 
type m

let x = 9.0<m^4>
let y = sqrt x

That is, sqrt knows it takes a u^2 and returns a u.

By on 11/7/2009 11:18 AM ()

Yes this works but there are too many situations where you do math which leads to exponentiation of real numbers to fractions and to modify all units is not a solution because you would have to have many different ones for different exponents

I understand that it would be probably impossible to implement exponentiation of real numbers to real numbers => is x^0.5 * x^0.5 equal to x or to x^0.9999?

But on the other hand, it could easily work with fractions => x^(1/2) * x^(1/2) = x

So the only solution, which I see now, is not to use units of measure for more complicated math tasks...

By on 11/9/2009 2:35 AM ()

modify all units is not a solution because you would have to have many different ones for different exponents

That's the job of type inference. Doesn't it work?You can call sqrt only when the unit power is even, but you need to give the exact unit only for constants. Type inference should figure out all the rest.

By on 11/9/2009 5:54 AM ()

Square root can be computed directly with
sqrt 4.0
or through exponentiation
4.0 ** 0.5
where

1
val ( ** ) : (float -> float -> float)
By on 11/7/2009 5:19 AM ()

Hi,

sorry for confusing you. I have noticed that I am not able to insert a left angle bracket even into code region to represent units of measure...

Take a look at my first post.

Best regards,

Oldrich

By on 11/7/2009 6:55 AM ()

No, there's no way to do that - only integral powers are allowed. If you were defining your own units, you could do something like:

1
2
3
4
[<Measure>]type half_s

[<Measure>]type s = half_s^2

and then write your expression in terms of half_s. You won't be able to do this with the built-in units, though. To be honest, it seems like an odd requirement - I can't think of a situation where fractional powers of units would naturally arise. Maybe it would be easier to work with the square of the quantity in question instead?

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