Wednesday, February 24, 2010

Animal Menstruation Pic

Cassidy Marie shipped


Beta


Release Candidate


Cassidy Marie shipped

The lucky and sleepless parents
Marika and Benjamin Gopp

Friday, February 12, 2010

Emu Cleaner Und Conditioner

F #, Units of Measure

By this week published Release Candidate of VS2010, has also done what in F #. Like Don Syme in his Blog writing is the F # compiler has been set up to version 2.0. This means F # it is mature to productive use (although many have already used it with earlier version). So finally time to seriously deal with F # and its brilliant features!

A feature I would like to write about today are Units of Measure or German units. This feature deals with the problem in the use of different units in the code. As the accident to the NASA Mars Climate Orbiter shows in 1999, it is still in errors due to the use of different units. Meanwhile in the U.S. in science and used technology, the metric system. A supplier, however, had reckoned in pounds and feet, which ultimately led to the fact that the Mars probe burned up.

This feature has only a relatively serious background. So that such errors do not creep into production code that F # is an advanced static code analysis. While units are annotated with attributes and tested for your use by the compiler for correctness. However, it does not examine only whether the given type is correct but also whether the function in which one uses this type of mathematically correct. Through the intelligent type inference in F # even the derivative units are determined.

Now how does it work? In C # you could hammer out some sort of type safety by creating a separate unit for types. Thus, the compiler would use the type of guarantee the type safety. But this is not possible, that is also checked for compliance with the rules of mathematics. This could perhaps be realized at run time in the appropriate units of measurement for defining rules. Ultimately, however, would be a test at run time not able to prevent the crash of a 100,000 km from the probe. Questions must be so much earlier, at compile done so.

Another note: Units of Measure can only floating point numbers are used! This is because you can not use just stupid units, but also physical parameters such as acceleration, etc. This would not work with integers or other types. (Indeed, one can use but Units of Measure with complex numbers or vectors)

For example

It first defines the units will use it as a type. These types can labeled with [\u0026lt;Measure>] . (This is what attributes from in F #. Failure to Chung from C # and VB attributes)

[\u0026lt;Measure>] type kg

[\u0026lt;Measure>] type s

[\u0026lt;Measure>] type m


Now we can write formulas. We want to know what speed we pay on earth, if we jump from a height. First, we define the height as a floating point unit and how this relates.

let height = 2.0 \u0026lt;m>


Now we define the gravity. This is an acceleration force: So Gravitationskonstate times meter per second squared

let gravity = 9.81 \u0026lt;m/s^2>


We can now calculate how much the speed with which one strikes the Earth .

let speed = sqrt (2.0 * gravity * height)


F # Interactive tells us that the speed is calculated in meters per second.

speed val: float = 14.00714104 \u0026lt;m/s>


According to

schlgt with 14 meters per second with a jump of 2 meters on the earth. Good to know!

In F # Power Pack Standardmaßeinheinten further defined, so that you can not every time all the laws of nature must recite. On the other hand, the question arises when we really need this feature. This shows again the great compliments to F # to existing C # code, but C # does not claim to solve in its entirety. So far still no porting considerations has been made, Units of Measure after C # or even in the CLR. We will have to see over time whether this and other features are ported to C #, or whether it then would be no need to use F #. That would be extremely bad!

Have fun trying out with F #

Benjamin