Drasil
Drasil copied to clipboard
`DefinedQuantityDict` constructors shouldn't use `Nothing` for their `Maybe UnitDefn`s
As part of #2677 and #2704, calls to dqd'
that don't have a UnitDefn
should be reworked to a different chunk type. Most other dqd'
calls were replaced with ucStaged
, but obviously trying to make a UnitalChunk
without a unit poses some problems.
Occurences
- All calls of
dqd'
inQuantities.Math
(shown below),SSP.Unitals
,SWHS.Unitals
-
fromEqn'
,fromEqnSt'
,fromEqnSt''
inChunk.Eq
- All
dqdNoUnit
calls (this function should eventually be removed?):Quantities.Math
,Quantities.Physics
,Quantities.SolidMechanics
,GlassBR.Unitals
, andPDController.Unitals
https://github.com/JacquesCarette/Drasil/blob/1ab7a8c2b875e8a7e6ff6bcc45e74c4e4bc38b32/code/drasil-data/lib/Data/Drasil/Quantities/Math.hs#L15 https://github.com/JacquesCarette/Drasil/blob/1ab7a8c2b875e8a7e6ff6bcc45e74c4e4bc38b32/code/drasil-data/lib/Data/Drasil/Quantities/Math.hs#L24-L26
I guess the first thing to do is to identify which chunk type that ought to be. Is there something that fits "just right"?
One thing to be wary of is that some things are without units (like pi) as they really are just scalars. Others things are Dimensionless quantities whose unit should be there but be 0 in all 7 dimensions.
Basically we need defined quantities without units, and defined quantities with units. And they probably should be different chunk types.
@JacquesCarette Based on the following code, it looks like the goal is eventually to get rid of MayHaveUnit
altogether
https://github.com/JacquesCarette/Drasil/blob/09365d7d1f5dc9b54e84a8d64cb601184456ea0c/code/drasil-lang/lib/Language/Drasil/Chunk/UnitDefn.hs#L66-L72
Since a UnitalChunk
is just a DefinedQuantityDict
with a UnitDefn
, removing the Maybe UnitDefn
from DefinedQuantityDict
would result in a chunk that fits "just right".
https://github.com/JacquesCarette/Drasil/blob/09365d7d1f5dc9b54e84a8d64cb601184456ea0c/code/drasil-lang/lib/Language/Drasil/Chunk/DefinedQuantity.hs#L28-L32 https://github.com/JacquesCarette/Drasil/blob/09365d7d1f5dc9b54e84a8d64cb601184456ea0c/code/drasil-lang/lib/Language/Drasil/Chunk/Unital.hs#L30-L32
Then, defined quantities without units would be DefinedQuantityDict
s, and defined quantities with units would be UnitalChunk
s. What would be the semantic consequences of this? As is, it seems like we are storing the unit information in two places for UnitalChunk
s, which seems like a design flaw - is there any rationale for this?
This could even be extended so that a scalar is a DefinedQuantityDict
, a dimensionless quantity is a UnitalChunk
with Nothing
for its unit, and a quantity with a "true" unit is a UnitalChunk
with Just _
for its unit. The main issue I can see with this is that UnitalChunk
would be an instance of HasUnit
(currently TempHasUnit
) that returns a Maybe
type; this is unintuitive and could lead to misunderstandings down the road.
I feel like I am slowly rediscovering old information and knowledge about how Drasil works, so any feedback would be appreciated!
The comments in TempHasUnit
probably reflect a period of time where I was thinking it would be better to not have Maybe
in interfaces but put them in data-structures instead. getUnit
is probably a bad name for the MayHaveUnit
method, since it seems that it will always success. tryGetUnit
?
Having said that: one issue that will arise with having the data-structures be 'pure' will be that we might not be able to create lists that mix things with/without a certain field. However, maybe we shouldn't be creating such lists at all! We're doing that right now to populate SystemInformation
. Probably we want to do that differently, using @balacij 's new chunk database and instead use lists of UIDs. (We might eventually even get rid of those lists entirely, but that can be a future step.)
From what I've understood about units, all "unitless" numbers do actually have a unit -- 1 (appearing as a "blackboard 1" symbol). So I agree with what @JacquesCarette's comment involving capturing dimensionless units (1 units), but I'm not sure if we need to make them a separate chunk type altogether (w.r.t. DefinedQuantityDict
).
I agree that dimensionless numbers have the unit "1". Radians are a good example because their SI unit is 1. In our document though we use rad (like in the Symbols for Double Pendulum). SI defines 1 rad = 1 I don't know if this means we are treating dimensionless quantities differently. I do know that I like the "rad" showing up, even though it just means 1.
Units and unit systems are quite complicated things. I'm going to dump some notes on the Units page of the wiki.