goldfirere / units

The home of the units Haskell package
95 stars 19 forks source link

Fix definition of `@~` #23

Closed goldfirere closed 10 years ago

goldfirere commented 10 years ago

I want this to work:

ratio :: (d1 @~ d2) => Qu d1 l n -> Qu d2 l n -> n
ratio x y = (x |/| y) # Number

But it doesn't, because d1 @~ d2 does not imply that Normalize (d1 @- d2) ~ '[]. Perhaps a different definition of @~ would work.

nushio3 commented 10 years ago

At least, the following works for the moment:

ratio ::  (Normalize (Reorder d1 d2 @@- d2) ~ '[], Fractional n) 
           => Qu d1 l n -> Qu d2 l n -> n

We can create a type synonym for Normalize (Reorder d1 d2 @@- d2) ~ '[] , meaning that we can infer that the two dimensions cancel each other.

a runnable example: https://github.com/nushio3/practice/blob/master/units/ratio.hs

goldfirere commented 10 years ago

Yes -- what you wrote was what I had in mind for @~. The outstanding question for me is whether the new @~ works in all cases where the old one did. My guess is "yes", but we have to test. This is where I wish we had a test suite.