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

Allow attaching metadata to datatype definitions #36

Open
L-as opened this issue Nov 17, 2022 · 0 comments
Open

Allow attaching metadata to datatype definitions #36

L-as opened this issue Nov 17, 2022 · 0 comments

Comments

@L-as
Copy link
Member

L-as commented Nov 17, 2022

Haskell already allows us to attach a small amount of metadata in the form of strictness-annotations and similar, however, it seems useful to distinguish between Haskell metadata and embedded metadata. The Haskell constructor taking a lazy argument doesn't necessarily mean the embedded constructor should, or vice versa.

There are two main ideas, the first one is adding a fake constructor with metadata:

newtype PMetadata metadata = PMetadata Void#

data PMyType ef = PMyType (ef /$ PInteger) (ef /$ PInteger)
  | PMyTypeMeta (PMetadata '[PScottEncoded])
  deriving stock (Generic)
  deriving anyclass (PHasRepr)

This essentially means the constructor doesn't exist, since you don't have to worry about it when matching,
and you can't construct it either.

The other trick is attaching metadata to individual fields like so:

data PMyType ef = PMyType (ef /$ PInteger) (PStrictField ef /$ PInteger)
  deriving stock (Generic)
  deriving anyclass (PHasRepr)

This doesn't affect PHs, nor how users interact with the type, but it allows backends to see that it should be strict.

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

No branches or pull requests

1 participant