Demo: Switch Sentence's SyCh constructor from UID to UIDRefs.#4716
Demo: Switch Sentence's SyCh constructor from UID to UIDRefs.#4716
Sentence's SyCh constructor from UID to UIDRefs.#4716Conversation
| -- | Find a chunk by a 'UIDRef', erroring if not found. | ||
| unhideOrErr :: IsChunk t => UIDRef t -> ChunkDB -> t | ||
| unhideOrErr tu cdb = fromMaybe (error "Typed UID dereference failed.") (unhide tu cdb) | ||
| unhideOrErr tu cdb = fromMaybe (error $ "Typed UID dereference failed for UID: " ++ show (raw tu)) (unhide tu cdb) |
There was a problem hiding this comment.
These messages just need to be upgraded a bit.
| -- | Get the raw 'UID' from a 'UIDRef'. | ||
| raw :: UIDRef t -> UID | ||
| raw (UIDRef u) = u |
There was a problem hiding this comment.
Being able to dump the UID from a UIDRef is helpful, in particular in the case of quantities in Drasil because: (a) we have many 'quantity' types, but (b) only insert a single variant of them (DefinedQuantityDicts) in the ChunkDB, so (c) de-referencing will always expect to look up a D-Q-D-. But I think we should be able to avoid exposing raw.
| IMs :: [Sentence] -> Fields -> [InstanceModel] -> DerivationDisplay -> SCSSub | ||
| -- | Constraints. | ||
| Constraints :: (HasUncertainty c, Quantity c, Constrained c, HasReasVal c, MayHaveUnit c) => Sentence -> [c] -> SCSSub | ||
| Constraints :: (IsChunk c, HasUncertainty c, Quantity c, Constrained c, HasReasVal c, MayHaveUnit c) => Sentence -> [c] -> SCSSub |
There was a problem hiding this comment.
We should switch all HasUID usage in drasil-lang to IsChunk.
| getUIDs (Ch TermStyle _ _) = [] | ||
| getUIDs (Ch PluralTerm _ _) = [] | ||
| getUIDs (SyCh a) = [a] | ||
| getUIDs (SyCh a) = [raw a] |
There was a problem hiding this comment.
This function now becomes tricky. What should the output type be? Previously: getUIDs :: Sentence -> [UID].
It is used as part of chunkRefs. Does this mean we need to re-design chunkRefs a bit? Should HasChunkRefs give us UnitypedUIDRefs instead of raw UIDs?
| -- | Look up a symbol given a chunk database and a 'UID' associated with the | ||
| -- symbol. Hack: Always uses 'DefinedQuantityDict' as the chunk type to look up, | ||
| -- despite that not being the _actual type_ of the chunk being looked up. | ||
| lookupSymb :: (IsChunk t, HasSymbol t) => PrintingInformation -> UIDRef t -> Symbol | ||
| lookupSymb pinfo u = sytyF (pinfo ^. stg) (findOrErr (raw u) (pinfo ^. sysdb) :: DefinedQuantityDict) | ||
| where sytyF Equational = eqSymb | ||
| sytyF Implementation = codeSymb |
There was a problem hiding this comment.
findOrErr (raw u) (pinfo ^. sysdb) :: DefinedQuantityDict here ignores the t type parameter! It could be looking up anything but we need to always resolve it to a DefinedQuantityDict here because: we only insert DefinedQuantityDicts (extract from other 'quantity'-like types) in the ChunkDB.
This will simplify work necessary for re-writing #4716. As a result of this, it was sensible to also replace `HasUID` usage in `NamedIdea` to `IsChunk` as well (this results in a smaller diff, and is sensible; `UID`s should be best kept as 'secret' as possible, even though this doesn't really do that).
This will simplify work necessary for re-writing #4716. As a result of this, it was sensible to also replace `HasUID` usage in `NamedIdea` to `IsChunk` as well (this results in a smaller diff, and is sensible; `UID`s should be best kept as 'secret' as possible, even though this doesn't really do that).
Contributes to #4541.
This PR already needs to be broken up, but it's helpful to have it live as a PR that I can potentially re-purpose.