-
Notifications
You must be signed in to change notification settings - Fork 26
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
Redesigning UnitalChunk
constructors
#3199
Comments
Numbering things the same as above.
I don't like Point 2 remains the thorniest. But |
@JacquesCarette I found (as best as I could) every instance of where a -- Chunk.Constrained
cuc' :: (IsUnit u) => String -> NP -> String -> Symbol -> u
-> Space -> [ConstraintE] -> Expr -> ConstrConcept
cuc' nam trm desc sym un space cs rv =
ConstrConcept (dqd (cw (ucs nam trm desc sym space un)) sym space uu) cs (Just rv)
where uu = unitWrapper un
-- Chunk.UncertainQuantity
uqc :: (IsUnit u) => String -> NP -> String -> Symbol -> u -> Space
-> [ConstraintE] -> Expr -> Uncertainty -> UncertQ
uqc nam trm desc sym un space cs val = uq (cuc' nam trm desc sym un space cs val)
uqcND :: (IsUnit u) => String -> NP -> Symbol -> u -> Space -> [ConstraintE]
-> Expr -> Uncertainty -> UncertQ
uqcND nam trm sym un space cs val = uq (cuc' nam trm "" sym un space cs val) This gives us the following break down: From
|
-- | Helper for getting the phrase from a 'NamedIdea' using it's UID. | |
phrase :: (HasUID n, NamedIdea n) => n -> Sentence | |
phrase n = sentenceTerm (n ^. uid) | |
-- | Helper for getting the plural of a phrase from a 'NamedIdea'. | |
plural :: (HasUID n, NamedIdea n) => n -> Sentence | |
plural n = sentencePlural (n ^. uid) |
I've logged the (hopefully) extensive list of uses of all UnitalChunk
constructors on this wiki page for further investigation.
Next steps on this issue: redesign the @JacquesCarette what do you think about the names |
There has been discussion throughout a few issues that seems to hinge on the constructors for
UnitalChunk
s; since they were so interconnected, I decided to list the issues I've noticed with the constructors and propose a new design that would better organize them. Please let me know what's good, what's bad, and what's missing!Note that I didn't address
ucuc
orucw
for this issue, since they are quite different and this issue is long enough.The Problems
1. Assuming the
Space
isReal
While a
UnitalChunk
is simply aDefinedQuantityDict
with aUnitDefn
, mostUnitalChunk
constructors create theDefinedQuantityDict
internally instead of having it passed as a parameter. Of these, most of them assume theSpace
to beReal
.Drasil/code/drasil-lang/lib/Language/Drasil/Chunk/Unital.hs
Lines 30 to 32 in 09365d7
While (as far as I can tell) most quantities have a
Real
Space
, I'm not sure if this should be assumed by the constructors for two main reasons.UnitalChunk
constructor, it is likely that we will eventually need a variant that does NOT assume that theSpace
isReal
. (This is actually the crux of What to do aboutdqd'
constructors that result in chunks that are instances ofHasSpace
? #3075, although I didn't quite understand what was actually happening.)Space
isReal
could be used, but isn't. For example, theUnitalChunk
constructorucs'
does not assume theSpace
to beReal
, yet most of its calls useReal
(all inData.Drasil.Quantities.Math
, 33/38 times in the unitals for GamePhysics, etc.) This is exacerbated when aUnitalChunk
constructor that does not assume theSpace
is passedReal
from a higher-level constructor.@JacquesCarette also mentioned that assuming the
Space
to beReal
is a hack in this comment, proposing we limit the scope of thedrasil-lang
constructors and have any "convenience" constructors be defined indrasil-utils
to be "imported 'qualified' ... to indicate that ... assumptions are being used." For example, all quantities inData.Drasil.Quantities.Math
use theReal
Space
. I'm not sure if this should be used for cases like SWHS (which has exactly oneConstrConcept
that does not have aSpace
ofReal
, shown below), but that seems like a different discussion.Drasil/code/drasil-example/swhs/lib/Drasil/SWHS/Unitals.hs
Lines 414 to 419 in 09365d7
2. Building from a
Concept c
or its partsWe have two constructors that build a
UnitalChunk
from aConcept c
...Drasil/code/drasil-lang/lib/Language/Drasil/Chunk/Unital.hs
Lines 64 to 67 in 09365d7
and five that build from "a given 'UID', term, and definition".
Drasil/code/drasil-lang/lib/Language/Drasil/Chunk/Unital.hs
Lines 74 to 78 in 09365d7
Since we have a similar number of instances of both approaches (by my count, 137 where the
Concept
is passed vs. 150 where theConcept
is built), I'm not sure if we should remove the constructor(s) that build(s) theConcept
. It might be good to force the user to create theConcept
themselves to ensure it is done correctly; this would also allow us to remove separateUnitalChunk
constructors for taking aString
or aSentence
for the description (shown below).Drasil/code/drasil-lang/lib/Language/Drasil/Chunk/Unital.hs
Lines 86 to 96 in 09365d7
Alternatively, we could also implement these extra constructors in
drasil-utils
. Since it is trivial to build aSentence
from aString
, we can also just remove theString
-based constructor.This has some implications, like potentially making the code less readable, as discussed in the wiki page for the
DefinedQuantityDict
chunk investigation. Also, sinceucs
is used incuc'
, we would need to tweak it as well.Drasil/code/drasil-lang/lib/Language/Drasil/Chunk/Constrained.hs
Lines 125 to 130 in 09365d7
3. Missing constructors for
Symbol
s that depend on theStage
.This is related to points 1 and 2 above, but we currently only have one
UnitalChunk
constructor for when theSymbol
is dependent on theStage
. As shown below, this constructor is based onuc'
and as such, assumes theSpace
isReal
(point 1) and builds theConcept
from the passed parameters (point 2).Drasil/code/drasil-lang/lib/Language/Drasil/Chunk/Unital.hs
Lines 80 to 84 in 09365d7
This is the core problem in #3074, where again, I didn't really understand what was happening. I was seeing if there is was a way to split a
Concept
into its parts to be passed into this constructor; there was a bit of an afterthought of creating another constructor that took aConcept
, but I didn't look into that too much.4. Poor Naming
This is a common thread for all constructors.
uc
anducs'
seem to be paired up (both haveConcept
s being passed whereucs'
also takes aSpace
), as douc'
anducs
(both haveConcept
s being built whereucs
also takes aSpace
), which seems inconsistent to me.makeUCWDS
is also the only constructor to not start with "uc
", which is also inconsistent.ucStaged
is also based onuc'
, not onuc
as one would expect.My Proposed Solution
The solution would address point 1 by not assuming the
Space
at all (although some helper functions that do could be created indrasil-utils
if desired). The main two constructors would beuc
anducStaged
. As per point 3,ucStaged
is a variant to allow forSymbol
s to depend on theStage
, and is based onuc
to resolve point 4.Depending on where we land on point 2, the following two constructors could also be included (either here or in
drasil-utils
). As mentioned above, these both only take aSentence
as the description (as opposed to aString
), although this is also not set in stone. As before, neither assumes theSpace
to beReal
, resolving point 1.ucNoConcStaged
is a variant for aSymbol
that depends on theStage
, as per point 3. Finally, they also have more descriptive names (a variant ofuc
that doesn't take aConcept
-> "noConcept
" ->NoConc
) which resolves point 4.The text was updated successfully, but these errors were encountered: