Skip to content

demo: Switch Sentence's Ch constructor's UID-based chunk references towards UIDRef-based ones.#4829

Draft
balacij wants to merge 1 commit intomainfrom
mvpTypedUIDRefSentenceChs
Draft

demo: Switch Sentence's Ch constructor's UID-based chunk references towards UIDRef-based ones.#4829
balacij wants to merge 1 commit intomainfrom
mvpTypedUIDRefSentenceChs

Conversation

@balacij
Copy link
Copy Markdown
Collaborator

@balacij balacij commented Mar 18, 2026

This will remove one of the major uses of termResolve' (the infamous issue mentioned in #4671).

However, this work needs to be broken up and better understood. Why are all of these changes necessary? I will attach a review.

(Yes, this fails the CI, I'm aware, that's not the point of this PR.)

references towards `UIDRef`-based ones.

This will remove one of the major uses of `termResolve'` (the infamous
issue mentioned in #4671).

However, this work needs to be broken up and better understood.

-- | Constructs a 'CodeDefinition' where the underlying 'CodeChunk' is for a variable.
qtov :: CanGenCode e => QDefinition e -> CodeDefinition
qtov :: (Typeable e, CanGenCode e) => QDefinition e -> CodeDefinition
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These Typeable constraints are a bit ugly to plaster everywhere. I'm not immediately sure how to deal with them, or if I'm just missing something obvious.

-- | Ch looks up the term for a given 'UID' and displays the term with a given 'SentenceStyle' and 'CapitalizationRule'.
-- This allows Sentences to hold plural forms of 'NamedIdea's.
Ch :: SentenceStyle -> TermCapitalization -> UID -> Sentence
Ch :: (TypeableChunk t, Idea t) => SentenceStyle -> TermCapitalization -> UIDRef t -> Sentence
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, Typeable here is ugly. Need to figure out how to deal with this nicely.

SentenceStyle can take on 3 values: Plural, Term, and Short. Plural corresponds to plural-full. We don't support plural-short. This needs to be split into two separate options.

Now, it's because this has the option to output short-form nouns that we put the constraint Idea on the chunk (Idea = NamedIdea + getA, where getA is an accessor for the short-form of a chunk's noun phrase). (explaining this is odd, we need to fix the descriptions). As a result, a lot of functions that previously formed Sentences using this constructor that only required NamedIdea constrained needed to be weakened to Idea.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is more than ugly - if it is needed, it points to a bad design. Maybe in UIDRef t?

Comment on lines +99 to +102
-- | Look up the plural form of a term given a chunk database and a 'UID' associated with the term.
lookupP' :: (TypeableChunk t, Idea t) => PrintingInformation -> UIDRef t -> TermCapitalization -> Sentence
lookupP' sm ur pCap = resolveCapP pCap $ c ^. term
where c = unhideOrErr ur (sm ^. sysdb)
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the bright side of this PR, we get to use unhideOrErr (which looks for a single chunk UID of a specific type) rather than termResolve' which tries to cast a chunk to $n$ different chunk types that have terms.

instance HasUID (ConstraintSet e) where uid = con . uid
-- | Finds the term ('NP') of the 'ConstraintSet'.
instance NamedIdea (ConstraintSet e) where term = con . term
instance Typeable e => NamedIdea (ConstraintSet e) where term = con . term
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, a wart. What's odd about this is that all types are supposed to have Typeable predefined for them by GHC. But GHC yells at us about unresolved constraints if these aren't explicitly here as well.

Also, HLS warns that this is a redundant constraint! However, GHC does not!

@balacij
Copy link
Copy Markdown
Collaborator Author

balacij commented Mar 19, 2026

The CI failed because a CI (glassBR) was not found. This makes sense because we only input IdeaDicts for raw-term declarations. We do not include CIs. We will need to fix that before this PR work may continue.

Copy link
Copy Markdown
Owner

@JacquesCarette JacquesCarette left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing the problem is deep in the database code.

Rather than Typeable down there, I would be tempted to use either Proxy or an explicit kind, or something like it. We want to not forget the type. Typeable lets us forget and then recover later. That's too 'dynamic'.

-- | A NamedIdea is a 'term' that we've identified (has a 'UID') as being worthy
-- of naming.
class IsChunk c => NamedIdea c where
class (Typeable c, IsChunk c) => NamedIdea c where
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the oddest Typeable, which is definitely going to propagate downstream. Why is this one needed?

-- | Ch looks up the term for a given 'UID' and displays the term with a given 'SentenceStyle' and 'CapitalizationRule'.
-- This allows Sentences to hold plural forms of 'NamedIdea's.
Ch :: SentenceStyle -> TermCapitalization -> UID -> Sentence
Ch :: (TypeableChunk t, Idea t) => SentenceStyle -> TermCapitalization -> UIDRef t -> Sentence
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is more than ugly - if it is needed, it points to a bad design. Maybe in UIDRef t?

@JacquesCarette
Copy link
Copy Markdown
Owner

As I suspected, this is all due to using Typeable in ChunkDB. As others suggest either Proxy or Tagged might be better.

I'm thinking maybe Tagged with DataKind which enumerates the known chunk types that go into ChunkDB. That way you maintain a single table, but with enough information retained about what type went in that you can restore it when you take it out -- without Typeable.

@balacij balacij marked this pull request as draft March 30, 2026 17:59
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

Successfully merging this pull request may close these issues.

2 participants