units-of-measurement

how do F# Units of Measure work

Has anyone had a chance to dig into how F# Units of Measure work? Is it just type-based chicanery, or are there CLR types hiding underneath that could (potentially) be used from other .net languages? Will it work for any numerical unit, or is it limited to floating point values (which is what all the examples use)? ...

Do you use "kibibyte" as a unit of measurement in your programs?

For decades, in the field of computing (except disk manufacturers), a KB (kilobyte) was understood to mean 1024 bytes. In the past few years, there has been a movement to use KiB ("kibibyte") to mean 1024 bytes, and change the meaning of kilobyte to be 1000 bytes, dooming us to many more years of confusion. On the other hand, the movemen...

How to pick what unit to display a value in?

I have a value and I known that it's units is meters^(mn/md) * kg^(kn/kd) * s^(sn/sd) * K^(Kn/Kd) * A^(An/Ad) Note: the exponents are rational, units of m^0.5 are valid The question is how to pick how to break down the units into something more compact for instance if md=kd=sd=Kd=Ad=1 mn=Kn=An=0 kn=1 sn=-1 I can use N/m I suspec...

What units of measure would you store engineering data in?

In our app, we currently live with the legacy of a decision to store all engineering data in our database in SI. I worry that we may run the risk of not having sufficient precision and accuracy in our database or in .NET numeric types. I am also worried that we may see artifacts of floating-point maths (although that is probably a quest...

Units of measure in C# - almost

Inspired by Units of Measure in F#, and despite asserting (here) that you couldn't do it in C#, I had an idea the other day which I've been playing around with. namespace UnitsOfMeasure { public interface IUnit { } public static class Length { public interface ILength : IUnit { } public class m : ILength { } ...

Natural Language Unit Conversion in PHP?

I'm looking for a library (preferably in PHP) that can extract weigh / height data from a string. I want my users to input something like "I weigh 80 k and I'm 1.8m tall" or even "220 lb" and "6' 1" and pass it through a function that can extract the quantity and the unit. Anyone know if there's something like that out there? ...

Where to do Conversions - Time zones, unit of measure etc.

Where in code should conversions be done? client, server, business, or db? We currently do conversions of timezones and unit of measure in our database and the performance is killing us and would like to move the logic. Where do you think the best location for this is? Thanks ...

How to generically remove F# Units of measure

I've got some data manipulation code which spits out csv at the end. I started upgrading it to add units of measure everywhere, but I now have a problem with my csv function: val WriteCSV : string -> 'a list array -> 'b list -> string -> unit (the parameters are fileName, column array, column headers, separator) Where I previously s...

F# compiler error FS0030, problems with the Value Restriction

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...

F# Units of measure - 'lifting' values to float<something>

When importing numbers from a csv file, I need to convert them to floats with unit. Currently I do this with an inline function: data |> List.map float |> List.map (fun n -> n * 1.0<m>) But I'm wondering if there is a more elegant way to do this - or do I have to create my own 'units' module with conversion functions? What would be ...

Conversion between different units of measurement in SQL (in Access)

I'm trying to program an access database but I'm using SQL for all my querying. I've got the database almost complete but I have one query that has me stumped. It is a database which contains recipes. I have a table in which I have all the conversions for cooking (Tablespoon to Teaspoon, Teaspoon to Cup, etc.). The user needs to be a...

F# Units of measure, problems with genericity

(I'm still banging on with units of measure in F#) I'm having a problem making 'generic' functions which take 'typed' floats. The following mockup class is intended to keep tabs on a cumulative error in position, based on a factor 'c'. The compiler doesn't like me saying 0.<'a> in the body of the type ("Unexpected type parameter in uni...

F# Units of measure, problems with genericity 2

Following on from this question, I still seem to be battling at the frontiers of what is possible, though I don't think that I'm doing anything particularly bleeding edge: type Vector2d = { X: float<'u>; Y: float<'u> } Gives me error FS0039: The unit-of-measure parameter 'u' is not defined. And type Vector2d = { X: float<_>; Y: flo...

C# Datastructure for multiple unit conversions

I have a c# app and I need to convert between 3 different units (say for example: litres, Gallons and Pints). The app needs to know about certain volumes of liquid say: 1 pint, 10 pints, 20 pints and 100 pints. I intend to do the calculations and hard code the values (not ideal but necessary), Im looking for a datastructure that will...

Why em instead of px?

I heard you should define sizes and distances in your stylesheet with em instead of in pixels. So the question is why should I use em instead of px when defining styles in css? Is there a good example that illustrates this? ...

WPF analogy for 'em' unit

What is the WPF analogy for the CSS em unit? ...

function for converting kilograms to pounds and ounces

I'd like to convert kilos into pounds and ounces e.g. if a user enters 10 kg then the function should return 22 lb and 0.73 oz Any ideas? ...

Datatype for unit of measurement in database

For my application I need to keep the prefered unit of measurement of a user. The possible units currently are: Liter (the unit the values in the rest of my database are stored in) Kilogram (varries with the density of the products) US Liquid Gallon (3.785411784 litres) US Liquid Quart (1/4th of above) UK Liquid Gallon (4.54609 litres...

How do I get the "Measurement Units" setting from OS X?

I want my app to display measurements in US or Metric based on the chosen setting in OS X's International preference pane. How do I get this piece of information from the OS in my code? ...

Cooking Units in Java

Are there any open source libraries for representing cooking units such as Teaspoon and tablespoon in Java? I have only found JSR-275 (http://jscience.org/jsr-275/) which is great but doesn't know about cooking units. ...