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

make Delayed type abstract #127

Merged
merged 5 commits into from
Apr 12, 2024
Merged

make Delayed type abstract #127

merged 5 commits into from
Apr 12, 2024

Conversation

jvoigtlaender
Copy link
Member

@jvoigtlaender jvoigtlaender commented Apr 11, 2024

@owestphal, wouldn't it be better to hide the data constructor of the newtype thus?

I've also been thinking about further replacing

newtype Delayed a = Delayed {unDelayed :: String} deriving (Eq, Typeable, Generic)

by

newtype Delayed a = Delayed String deriving (Eq, Typeable, Generic)

instance Show (Delayed a) where
  show (Delayed str) = str

and

    Left err -> reject $ case parse (fully tokenSequence) "" (unDelayed ans) of

by

    Left err -> reject $ case parse (fully tokenSequence) "" (show ans) of

Is there a need somewhere to really have the default derived Show instance for Delayed, i.e., with "Delayed " being output?

@jvoigtlaender
Copy link
Member Author

For symmetry with parse, maybe the order of arguments of parseDelayed should be flipped?

newtype Delayed a = Delayed String deriving (Eq, Typeable, Generic)

instance Show (Delayed a) where
show (Delayed str) = str
Copy link
Member Author

Choose a reason for hiding this comment

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

Is there even a need for a Show instance for Delayed now?

Copy link
Member

Choose a reason for hiding this comment

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

At the moment it is used for the Hashable (Delayed a) instance in Autotool. At the "expense" of a hashable dependency the instance could be defined here instead (making it also non-orphan).

Copy link
Member Author

Choose a reason for hiding this comment

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

But why is Hashable (Delayed a) even needed? I guess I am still struggling to get to grips with the role of Delayed. There shouldn't be a task type that has Delayed as its input type, nor inside a configuration or instance type, right? That is the whole point of having things like

type CnfString = String
instance Partial TruthTableMaxterm MaxInst CnfString where

in Autotool, not

instance Partial TruthTableMaxterm MaxInst (Delayed Cnf) where

right?

Copy link
Member

Choose a reason for hiding this comment

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

You are right. It is not needed. I transformed the actual string input too early in a few cases where completeGrade is used inside of toReporterWithGlobalPics which requires Hashable inputs.

Copy link
Member Author

Choose a reason for hiding this comment

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

Does something similar apply to the Eq, Typeable, Generic instances?

Due to the peculiar role of Delayed, the pull request's intention really was to "isolate" it somewhat from the rest of the code via making it as abstract as possible. Any provided type class instance of course makes it a bit less abstract, since one can then learn something about internals of a delayed value.

@owestphal
Copy link
Member

Should the signature of parseDelayedRaw :: Parser b -> Delayed a -> Either ParseError b also be restricted to achieve better isolation? With the current signature, the internal string is fully recoverable.

The obvious Parser () -> Delayed a -> Either ParseError () might be too restrictive though. E.g., when we want to count the number of parentheses (see #126).

@jvoigtlaender
Copy link
Member Author

I'd say that parseDelayedRaw as a name is good enough in order to convey that one is dealing with internals if one uses it.

After all, the point of the abstraction is not really to guard against "malicious actors" here, but against "accidental misuse". If someone calls parse...Raw, like unsafe..., they have it coming. 😄

@jvoigtlaender jvoigtlaender merged commit 41d5b64 into master Apr 12, 2024
19 checks passed
@jvoigtlaender jvoigtlaender deleted the delayed-barrier branch April 12, 2024 12:55
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