-
Notifications
You must be signed in to change notification settings - Fork 1
wip #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
wip #4
Conversation
Hi Aster ! Thanks a lot for proposing a contribution to this library ! Yes it's quite confusing indeed. The reason I separated Angle units from NonAngle units is because this library handles two different unit systems:
In order to avoid duplications, However, |
It is pretty close, but you can simplify it:
is used specifically for units whose conversion is more complicated than a mere factor conversion. Namely in the case of
For units like
which will declare the instances for TL;DR : You should use |
Also I just realized (I'm french, I'm not used to those units) that there are two different system of units in use in some of the countries of the Common wealth:
In terms of folder organization, I was thinking it would be best to separate them as independant unit systems, meaning there would be a module And we would keep What do you think @Aster89 ? |
Ok, so this
maps to this: convert-units/src/Data/Units/AngleSI/System.hs Lines 21 to 26 in fc3732c
And this:
maps to this:
vs, I suppose..., this?
Yeah, I can give that a go, but before that, for my sanity, can I submit a change where I do a few little things like these?
|
Yes, exactly. In fact, type Angle = NormalizeDim (Length ./. Length) is just a convoluted way of writing type Angle = NoDim but following the SI derived unit conventions that state that radians are the same as As a consequence,
Sure please go ahead! Thanks a lot for proposing such contributions :-) |
Ehmmmm... in an attempt to Build profile: -w ghc-9.12.2 -O1
In order, the following will be built (use -v for more details):
- convert-units-0 (test:convert-units-test) (first run)
Preprocessing test suite 'convert-units-test' for convert-units-0...
Building test suite 'convert-units-test' for convert-units-0...
ghc-9.12.2: could not execute: hspec-discover but it happens also on fc3732c. Any idea? Oh, I've created the Never mind, found an answer at haskell/actions#254 (comment): adding build-tool-depends: hspec-discover:hspec-discover in test-suite convert-units-test allows me to successfully run |
Not quite doable, as |
Yes, this is a bit annoying, I agree. However, I haven't figured it out yet, and I'm not sure it is desirable to authorize anything else as Rational. Here is why:
which is implemented as follows: mkConvFactorInstance unitName fctr = [d|
instance Fractional a => ConversionFactor $(conT unitName) a where
factor = $(litE (RationalL fctr))
|] For the case of instance Floating a => ConversionFactor Degree a where
factor = pi / 180
{-# INLINE factor #-} But how do you actually implement this in TH ? Maybe it is doable but I personally don't know how. First trymkConvFactorInstance :: (Floating b, Quote m) => Name -> b -> m [Dec]
mkConvFactorInstance unitName fctr =
[d|
instance Floating a => ConversionFactor $(conT unitName) a where
factor = $___
|] it is unclear to me how to use But it would also mean we always ask the Maybe the solution would be to have two TH constructors: Second tryThe following code compiles fine: mkConvFactorInstance :: (Real a, Quote m) => Name -> a -> m [Dec]
mkConvFactorInstance unitName fctr =
let fctrRat = toRational fctr in
[d|
instance Fractional a => ConversionFactor $(conT unitName) a where
factor = $(litE (RationalL fctrRat))
|] But this is absolutely wrong, because we are not actually using |
Personally I use |
Hi, @AliceRixte , can you please give a look at this work in progress? I've left quite a few comments with questions. |
Hi @Aster89 ! It looks things are advancing! I'm currently in hollydays, I'll make a code review when I'm back (in a bit more than a week) |
Hi there. I found this project on Haskell Weekly.
Is #3 expecting something like this?
I don't really understand the dir structure... As in, what's the relation between the line
$(mkUnitNoFactor "Celsius" "°C" ''Temperature)
which is about temperature in Celsious degree, and the pathData/Units/SI/Derived/NonAngle.hs
of the file that contains it? How is "temperature in celsius" an "SI derived non-angle unit"? I mean, every unit is a non-angle unit if it... a non-angle unit.