Skip to content
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

Quoted unit functions don't compose. #72

Open
philderbeast opened this issue Apr 18, 2020 · 2 comments
Open

Quoted unit functions don't compose. #72

philderbeast opened this issue Apr 18, 2020 · 2 comments

Comments

@philderbeast
Copy link
Collaborator

-- Quoted units without a value specialise to functions we can use to attach
-- units to unitless numeric values.
--
-- >>> [u| m / s^2 |] 9.8
-- [u| 9.8 m / s^2 |]
--
-- >>> [u| m s^-2 |] 9.8
-- [u| 9.8 m / s^2 |]
--
-- >>> [u| m / s / s |] 9.8
-- [u| 9.8 m / s^2 |]
--
-- >>> [u| s^-2 m |] 9.8
-- [u| 9.8 m / s^2 |]
--
-- Composition of these functions doesn't work as I'd expect, applying
-- composed units to the numeric value.
--
-- >>> [u| m |] $ [u| s^-2 |] 9.8
-- [u| [u| 9.8 s^-2 |] m |]
--
-- >>> [u| s^-2 |] $ [u| m |] 9.8
-- [u| [u| 9.8 m |] s^-2 |]
--
-- >>> [u| m |] . [u| s^-2 |] $ 9.8
-- [u| [u| 9.8 s^-2 |] m |]
--
-- >>> [u| s^-2 |] . [u| m |] $ 9.8
-- [u| [u| 9.8 m |] s^-2 |]
--
-- >>> [u| m |] [u| 9.8 s^-2 |]
-- [u| [u| 9.8 s^-2 |] m |]
--
-- >>> [u| s^-2 |] [u| 9.8 m |]
-- [u| [u| 9.8 m |] s^-2 |]
--
-- >>> [u| m |] . [u| s^-1 |] . [u| s^-1 |] $ 9.8
-- [u| [u| [u| 9.8 s^-1 |] s^-1 |] m |]
@philderbeast
Copy link
Collaborator Author

I've left the reproduction in the tutorial for now.

-- Composition of these functions doesn't work as expected. It doesn't apply
-- composed units to the numeric value.
--
-- >>> [u| m |] $ [u| s^-2 |] 9.8
-- [u| [u| 9.8 s^-2 |] m |]
-- >>> [u| s^-2 |] $ [u| m |] 9.8
-- [u| [u| 9.8 m |] s^-2 |]
-- >>> [u| m |] . [u| s^-2 |] $ 9.8
-- [u| [u| 9.8 s^-2 |] m |]
-- >>> [u| s^-2 |] . [u| m |] $ 9.8
-- [u| [u| 9.8 m |] s^-2 |]
-- >>> [u| m |] [u| 9.8 s^-2 |]
-- [u| [u| 9.8 s^-2 |] m |]
-- >>> [u| s^-2 |] [u| 9.8 m |]
-- [u| [u| 9.8 m |] s^-2 |]
-- >>> [u| m |] . [u| s^-1 |] . [u| s^-1 |] $ 9.8
-- [u| [u| [u| 9.8 s^-1 |] s^-1 |] m |]

@adamgundry
Copy link
Owner

This is a very good observation. At the moment we have

[u| m |] :: a -> Quantity a (Base "m")

Instead, I think we should change this to:

[u| m |] :: Quantity a u -> Quantity a (Base "m" *: u)

That is, when the quasiquoter is used in an expression without a number, it produces a function that multiplies a polymorphic value by the given units. Since literals are dimensionless, I think we get this:

[u| m |] 1 == [u| 1 m |] :: Num a => Quantity a (Base "m")
[u| m |] $ [u| s^-2 |] 9.8 == [u| 9.8 m s^-2 |] :: Fractional a => Quantity a [u| m s^-2 |]
[u| m s^-2 |] :: Quantity a u -> Quantity a ([u| m s^ -2 |] *: u)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants