Hi Jake,

I agree with Jeffrey's response mostly, but want to clarify that Unitful is 
not strictly focused on the SI system. You'll see that you can use units of 
acre-feet, very much not an SI unit, which could be useful if you happen to 
manage a water reservoir in the United States, I guess.

If you were instead asking whether or not you could write methods that 
dispatch on the dimensions of a unit, the current answer is no, although 
maybe that could change eventually.

Best,
Andrew

On Wednesday, February 17, 2016 at 3:25:37 AM UTC-8, Jeffrey Sarnoff wrote:
>
> Jake,
>
> Julia's type system is well suited to do just that.  Unitful is focused on 
> units in SI system, things like Meters, Kilograms and Joules.
>
> One approach to abstract units like size, where size may be relative to 
> the number of pixels on a screen or the width of a page,
> is define your own type, a kind of size relative to something.  In your 
> example, s is not a unit of measure (strictly speaking);
> s is a quantity interpreted in terms of some absolute or relative unit of 
> measure -- 5 pixels, 1/4 page.  Because pixels and pages
> are not always the same number of, say, millimeters, using SI units for 
> that abstraction likely is not what you want.
>
> If you want more guidance, please give some more context.
>
> On Wednesday, February 17, 2016 at 4:43:13 AM UTC-5, Jake Rosoman wrote:
>>
>> Is it possible to talk about abstract types of units like size. e.g 
>> `drawline(s::Size) = ...`?
>>
>> On Saturday, February 13, 2016 at 9:23:22 AM UTC+13, Andrew Keller wrote:
>>>
>>> I'm happy to share a package I wrote for using physical units in Julia, 
>>> Unitful.jl <https://www.github.com/ajkeller34/Unitful.jl>. Much credit 
>>> and gratitude is due to Keno Fischer for the SIUnits.jl 
>>> <https://www.github.com/keno/SIUnits.jl> package which served as my 
>>> inspiration. This is a work in progress, but I think perhaps a serviceable 
>>> one depending on what you're doing. 
>>>
>>> Like SIUnits.jl, this package encodes units in the type signature to 
>>> avoid run-time performance penalties. From there, the implementations 
>>> diverge. The package is targeted to Julia 0.5 / master, as there are some 
>>> limitations with how promote_op is used in Julia 0.4 (#13803) 
>>> <https://github.com/JuliaLang/julia/pull/13803>. I decided it wasn't 
>>> worth targeting 0.4 if the behavior would be inconsistent. 
>>>
>>> Some highlights include:
>>>
>>>    - Non-SI units are treated on the same footing as SI units, with 
>>>    only a few exceptions (unit conversion method). Use whatever weird 
>>>    units you want.
>>>    - Support for units like micron / (meter Kelvin), where some of the 
>>>    units could cancel out but you don't necessarily want them to.
>>>    - Support for LinSpace and other Range types. Probably there are 
>>>    still some glitches to be found, though.
>>>    - Support for rational exponents of units.
>>>    - Some tests (see these for usage examples).
>>>
>>> Please see the documentation for a comprehensive discussion, including 
>>> issues / to do list, as well as how to add your own units, etc.
>>> Comments and feedback are welcome.
>>>
>>> Best,
>>> Andrew Keller
>>>
>>

Reply via email to