by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
Alex Cruise
@acruise
Yeah, I'm not even confident this is a good use case for Libra, it's just the first units library for Scala I stumbled on that seemed workable :)
I was briefly going down a rabbit hole of just defining an enum for units, but started to realize it would get combinatorial :)
Zainab Ali
@zainab-ali

All units libraries assume that you know what units you're dealing with at compile time, and effectively perform a compile time verification that the units you expect are the ones you actually have. You can still use libra for units known at runtime as long as you perform a runtime check that refines your unit type. For example, I can write a function with the following signature

def refineMetre(possibleMetre: String): NotAMetre Either QuantityOf[Metre] = ...
def refineSecond(possibleSecond: String): NotASecond Either QuantityOf[Second] = ...

The following code will (correctly) fail to compile:

for {
  myMetre <- refineMetre("foo")
  mySecond <- refineSecond("bar")
} yield myMetre + mySecond
The refineMetre and refineSecond methods don't exist yet, but it would be really cool to have a libra-refined compat library which could provide them. It's on my todo list :smile:
The above code would work for use cases such as reading config, where you know what units you expect. On the other hand, if you're communicating with an external system and you really have no idea what units you expect, things become more difficult.
Zainab Ali
@zainab-ali
You could potentially model your type as a coproduct of quantities, but that would quickly get complicated. You'd need to think long and hard about the kinds of calculations you want to perform, and what kind of evidence you'd need to perform it.
In cases like these, I tend to start wondering how I'd go about it in Idris, and why it isn't possible to do in Scala
Rob Norris
@tpolecat
@zainab-ali I have some quantities that are measured in conventional units where the same dimension occurs several times at different scales, for example spectral illuminance is measured in ergs (kg m^2 / sec^2) / sec / cm^2 / angstrom which includes meters in the energy term, centimeters in the surface area term, and angstroms in the wavelength term. I guess the strategy is to normalize to meters and deal with the constant factor difference as a display issue?
Not a complaint, I'm just trying to figure out the best way to think about this since we have a lot of weird conventional units in physics/astronomy.
Alex Cruise
@acruise
@tpolecat have you looked at Squants?
Rob Norris
@tpolecat
Yes we’re using it now but it’s based on floating point which I don’t like.
Alex Cruise
@acruise
aha
Rob Norris
@tpolecat
Nothing can ever be equal to anything else so it ends up infecting things.
Alex Cruise
@acruise
what's the big deal, it's not like you ever deal with huge quantities like the distances between sta---oh wait
Rob Norris
@tpolecat
Haha right.
We have to measure things in parsecs and in picometers.
Alex Cruise
@acruise
I've been looking for what I guess you might call a symbolic units library
Rob Norris
@tpolecat
I think Libra is close to what we want.
Alex Cruise
@acruise
cool!
I want to remember metadata that the numbers that are going to show up in this field in the future are m/s but I don't want to compile stuff every time a record shows up, I just want to be able to warn someone when they try to add an m/s to an attoparsec/microfortnight
I basically want a symbolic, serializable representation of the unit itself, not a quantity in that unit
But because units are composable in an algebraic system, I can't just have a flat list of units, it would get big
Rob Norris
@tpolecat
So you need to do this dynamically rather than statically?
Alex Cruise
@acruise
I would be fine with having enums called "metres" and "seconds" but it seems dumb to have "m/s" and "m/s²"
yes!
I don't know the units of particular fields until very late at runtime (if at all)
Rob Norris
@tpolecat
I see, ok.
Alex Cruise
@acruise
I need to be able to "shut up and take my data" from the user's stream, and only later when they decide to be nice and label some stuff, I'll gain the ability to say "hey, you're trying to add a distance and a volume, can u not"
like, they're writing a query in a DSL, not writing scala code
Rob Norris
@tpolecat
It kind of sounds like you want a runtime equivalent of what Libra tracks statically.
Alex Cruise
@acruise
yup
I don't mind writing all the runtime stuff myself, I would prefer to draw on someone else's library of units and their relationships though :)
Alex Cruise
@acruise
someone suggested a little codegen where I would basically render metres => 1.meter and seconds as 1.second as scala snippets, then when a user tried to divide them I would glue the snippets together and see if it compiled :laughing:
which... a few months ago codegen seemed like a terrible idea to me, but I've been committing that sin recently and it's not so bad at all
Nicolas Rinaudo
@nrinaudo
Is there any plan to cross-release to 2.13?
If it's mostly a problem of manpower / bandwidth, I can have a got at it
Zainab Ali
@zainab-ali
Hi @nrinaudo ! Cross releasing to 2.13 is certainly on the agenda. It should be fairly simple to do, but manpower is always appreciated :smile: . I've created #70 to track it
Nicolas Rinaudo
@nrinaudo
@zainab-ali great to hear! I'm in the midst of my own 2.13 migration horror story, but once I'm done, if #70 still needs help, I'll be happy to tackle it
Zainab Ali
@zainab-ali
@nrinaudo I have a WIP in #71, but it needs a bit more work for microsites. Almost there! :smiley:
It's pretty late here, so I'll leave it for now and take another stab at it tomorrow
Zainab Ali
@zainab-ali
Version 0.6.0 has been released with support for 2.13 :tada:
The docs build on master is failing because of some dependency issues - I'll look into these tomorrow
^^ @nrinaudo :smile:
Nicolas Rinaudo
@nrinaudo
Thanks!
did you end up having to drop tut and move to mdoc in the end?
Zainab Ali
@zainab-ali
No, still on tut, but I'm planning on giving it a try
For the moment, the docs and microsite are only published on the 2.12 build
Nicolas Rinaudo
@nrinaudo
ah, makes sense
after playing extensively with both, I find that:
  • mdoc is the best alternative to write documentation
  • tut is still the only tool that works to process slides and statically verify your talks
Nicolas Rinaudo
@nrinaudo
Yes, I can confirm that the artifacts are available and that they pass all (my) tests on both 2.12.8 and 2.13.0
thank you so much, @zainab-ali !