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

Define a Lift version for Version and related data types #68

Closed
RyanGlScott opened this issue Oct 10, 2023 · 6 comments · Fixed by #69
Closed

Define a Lift version for Version and related data types #68

RyanGlScott opened this issue Oct 10, 2023 · 6 comments · Fixed by #69

Comments

@RyanGlScott
Copy link

RyanGlScott commented Oct 10, 2023

It is very useful to be able to call the version function within a Template Haskell splice so that one can throw a compile-time error if the version number is malformed:

ver :: Text -> Q Exp
ver nm =
  case Versions.version nm of
    Left err -> fail (errorBundlePretty err)
    Right v  -> lift v

Currently, this function doesn't work out of the box, as the Version data type (which version returns) does not define a Lift instance. As a result, we have to define our own orphan Lift instances to make this work.

Would you be OK with defining the Lift instances directly in the versions library? Something like this would suffice:

deriving instance Lift Chunk
deriving instance Lift Chunks
deriving instance Lift Release
deriving instance Lift Version
RyanGlScott added a commit to GaloisInc/what4 that referenced this issue Oct 10, 2023
`versions-6.0.*` removes the `VChunk` data type, which `what4` defines an
orphan `Lift` instance for. This requires some CPP to fix up. This is somewhat
messy, and in an ideal world, we'd move these orphan instances directly to the
`versions` library. (See also fosskers/versions#68.)

Fixes #240.
RyanGlScott added a commit to GaloisInc/what4 that referenced this issue Oct 10, 2023
`versions-6.0.*` removes the `VChunk` data type, which `what4` defines an
orphan `Lift` instance for. This requires some CPP to fix up. This is somewhat
messy, and in an ideal world, we'd move these orphan instances directly to the
`versions` library. (See also fosskers/versions#68.)

Fixes #240.
@fosskers
Copy link
Owner

Sure. Can you suggest a unit test that could be used to verify it?

@fosskers fosskers linked a pull request Oct 11, 2023 that will close this issue
@fosskers
Copy link
Owner

@RyanGlScott Can you test the linked PR and see if it works for you? If so I'll make a release.

@RyanGlScott
Copy link
Author

Thanks, @fosskers! That PR gives me exactly what I need.

Can you suggest a unit test that could be used to verify it?

The way we are using this functionality in the what4 library is something like:

ver :: Text -> Q Exp
ver nm =
  case Versions.version nm of
    Left err -> fail (errorBundlePretty err)
    Right v  -> lift v

... $(ver "0") ...

So you could test something like $(ver "0") == Version {_vEpoch = Nothing, _vChunks = Chunks (Numeric 0 :| []), _vRel = Nothing, _vMeta = Nothing}, or perhaps even prettyVer $(ver "0") == "0".

You could also test that supplied an invalid version throws a compile-time error, e.g., $(recover [| () {- Recovery fallback -} |] (ver "!!!")) == ().

@fosskers
Copy link
Owner

Thanks a lot, I'll incorporate those!

@fosskers
Copy link
Owner

Released as 6.0.2.

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 a pull request may close this issue.

2 participants