units-of-measurement

Compile-time constraints for strings in F#, similar to Units of Measure - is it possible?

爱⌒轻易说出口 提交于 2019-11-28 10:55:23
I'm developing a Web application using F#. Thinking of protecting user input strings from SQL, XSS, and other vulnerabilities. In two words, I need some compile-time constraints that would allow me discriminate plain strings from those representing SQL, URL, XSS, XHTML, etc. Many languages have it, e.g. Ruby’s native string-interpolation feature #{...} . With F#, it seems that Units of Measure do very well, but they are only available for numeric types. There are several solutions employing runtime UoM (link) , however I think it's an overhead for my goal. I've looked into FSharpPowerPack, and

F# Units of measure, problems with genericity

我只是一个虾纸丫 提交于 2019-11-28 08:47:51
问题 ( 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 unit-of-measure literal"). ///Corrects cumulative error in position based on s and c type Corrector(s_init:float<'a>) = let deltaS ds c = sin (ds / c) /

F# Ununit - reunit inside a function

可紊 提交于 2019-11-28 08:46:27
问题 This question is closely related to these ones (1, 2, 3) I'm using an external library which doens't (yet) handle units of measure. I want to be able to 'ununit' values before I pass them in, then 'reunit' them when I get the results back. The catch is that I'd like to avoid being forced to declare WHICH units in advance. Example snippet let ExternalNonUnitAwareFunction s = s + 1. let MyUnitAwareClient (s:float<'u>) = //' //1. this option "flattens" to no unit, or fixes to first inferred unit

How do I convert pt to sp?

喜夏-厌秋 提交于 2019-11-28 04:52:48
I am a visual designer, working on an android design and I"m trying to spec my PSD file for our engineers. I cannot seem to find any documentation regarding the conversion of point size to SP for the type in any Android documentation. (Just that SP should be used for type). The problem is that it depends on the density. Really, they're not good measurements to try to compare. Points : There are 12 points in a pica, 6 picas per inch, so 72 (more accurately 72.27) points per inch. Device-Independent Pixels (DP) : These will be equal to the pixel size for MDPI displays, 1.5x the pixel size for

How do I know which is the default measure system (imperial or metric) on iOS?

蓝咒 提交于 2019-11-28 04:29:21
How do I know which is the default measure system (imperial or metric) on iOS ? How do I get this preference from the device settings, so I know what to display in my app ? thanks The NSLocale can tell you: NSLocale *locale = [NSLocale currentLocale]; BOOL isMetric = [[locale objectForKey:NSLocaleUsesMetricSystem] boolValue]; Only three countries do not use the metric system: the US, Liberia and Myanmar. The later uses its own system, the former two use Imperial Units. Apples documentation says (emphasis mine): NSLocaleUsesMetricSystem The key for the flag that indicates whether the locale

Physical constants in R

只谈情不闲聊 提交于 2019-11-28 03:43:57
问题 Just curious - is there a package or dataset somewhere containing values for physical constants? I only ask because I've now typed in 273.15 (Celsius to Kelvin conversion) wrong several times. =) 回答1: The packages marelac and dielectric both have some physical constants, but not that one in particular. marelac::convert_T will do the temperature conversions. 回答2: It's a fairly large task to assemble this information but some of the thermodynamic constants are available in marelac: > convert_T

Unit Conversion in Python

让人想犯罪 __ 提交于 2019-11-28 03:06:17
I'm working on a project that lets users track different data types over time. Part of the base idea is that a user should be able to enter data using any units that they need to. I've been looking at both units: http://pypi.python.org/pypi/units/ and quantities: http://pypi.python.org/pypi/quantities/ However I'm not sure the best way to go. From what I can tell, quantities is more complex, but includes a better initial list of units. Christopher Bruns I applaud use of explicit units in scientific computing applications. Using explicit units is analogous brushing your teeth. It adds some

WPF analogy for 'em' unit

回眸只為那壹抹淺笑 提交于 2019-11-28 00:28:32
问题 What is the WPF analogy for the CSS em unit? 回答1: AFAIK, there isn't one right now. But you can make your desire for this known here. One alternative (and I don't know if this is possible either) would be to measure how big the desired font is, then take that as your "ems" unit, then scale using those "units" instead. 回答2: Here is what I did. Created a MarkupExtension that converts Font size to EM based on font assigned on Window. I would like to thank http://10rem.net/blog/2011/03/09

When specifying a 0 value in CSS, should I explicitly mark the units or omit?

核能气质少年 提交于 2019-11-27 17:06:22
问题 This is more of a 'philosophy' argument, but I'd like to know what the recommended practice here. I'm not setting it up as a Wiki yet in case there is an 'official' answer. Obviously, there is no difference between 0px and 0em or whatever, so one could simply specify 0 and the units are redundant (see CSS difference between 0 and 0em). Some of the folks who answered that question argued that one should always omit the units. However, it seems to me that omitting the unit is more error-prone,

How do F# units of measure work?

隐身守侯 提交于 2019-11-27 13:13:26
问题 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)? 回答1: According to a response on the next related blog post, they are a purely static mechanism in the F# compiler. So there is no CLR representation of the units data. Its not