-
Notifications
You must be signed in to change notification settings - Fork 1
Export Arg/Id Patterns #135
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this warrants a minor version bump. Add @since
s to the pattern synonyms and (new) constructor names to go along with the Haddocks, and update the changelog.
-- | This is the *safe* read-only pattern | ||
pattern UnId :: Word64 -> Id | ||
pattern UnId w <- Id w | ||
|
||
-- | This is the *unsafe* pattern. | ||
-- This should ONLY ever be used for tests and you should | ||
-- NEVER use this to construct Ids manually. | ||
pattern UnsafeId :: Word64 -> Id | ||
pattern UnsafeId w = Id w | ||
|
||
{-# COMPLETE UnId #-} | ||
|
||
{-# COMPLETE UnsafeId #-} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can do it like this. In Covenant.Internal.Term
, define
newtype Id = UnsafeId Word64
...
Export Id(..)
. Then, in Covenant.ASG
, import Id (UnsafeId)
, then define
pattern UnId :: Word64 -> Id
pattern UnId w64 <- UnsafeId w64
{-# COMPLETE UnId #-}
Then export Id (UnId)
from Covenant.ASG
.
-- | This is the 'safe' pattern which can be used anywhere to | ||
-- deconstruct an arg | ||
pattern UnArg :: DeBruijn -> Index "arg" -> Arg | ||
pattern UnArg db i <- Arg db i _ | ||
|
||
-- | This is the *unsafe* pattern, which should NEVER | ||
-- be used to manually construct 'Arg's in an AST, and should | ||
-- ONLY ever be used for tests. | ||
pattern UnsafeArg :: DeBruijn -> Index "arg" -> ValT AbstractTy -> Arg | ||
pattern UnsafeArg db i t = Arg db i t | ||
|
||
{-# COMPLETE UnArg #-} | ||
|
||
{-# COMPLETE UnsafeArg #-} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same story.
We need these to write the code generator, unfortunately.
This is a bit of a mess (partly due to me needing to get this done ASAP today) in that we have
We could remove the non-pattern constructor exports from there... but it'd require a decent amount of fix-up that I do not have the time to do right now. If you suggest it I will be happy to do that later/tomorrow.