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

Provide a QuasiQuoter for UUID literals #41

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jessekempf
Copy link

No description provided.

@jessekempf jessekempf force-pushed the add_isstring branch 2 times, most recently from 1202998 to 4ff5bb7 Compare July 26, 2018 21:01
@jessekempf
Copy link
Author

@hvr: Can this be merged?

@hvr
Copy link
Collaborator

hvr commented Aug 18, 2018

@jessekempf To be honest I'm not a fan of supporting string-literals which cannot be statically validated at compile time and would thus be runtime landmines. I'm rather considering offering a QuasiQuoter instead.

@jessekempf jessekempf changed the title Give UUID an IsString instance Provide a QuasiQuoter for UUID literals Aug 22, 2018
@jessekempf jessekempf force-pushed the add_isstring branch 3 times, most recently from 301745d to a0bce93 Compare August 22, 2018 10:09
@jessekempf
Copy link
Author

@hvr: By your command.

@@ -0,0 +1,30 @@
{-# LANGUAGE TemplateHaskell #-}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we need this extension enabled? (NB: if we enable this, uuid stops working on TH-less GHCs)

Copy link
Author

Choose a reason for hiding this comment

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

It's needed to be able to capture Data.UUID.fromWords for the uuid QuasiQuoter. With it turned off:

technopancake-2:uuid jessekempf$ cabal test
Resolving dependencies...
Configuring uuid-1.3.13...
Preprocessing library for uuid-1.3.13..
Building library for uuid-1.3.13..
[9 of 9] Compiling Data.UUID.Quasi  ( Data/UUID/Quasi.hs, dist/build/Data/UUID/Quasi.o )

Data/UUID/Quasi.hs:18:41: error:
    • Syntax error on 'fromWords
      Perhaps you intended to use TemplateHaskell or TemplateHaskellQuotes
    • In the Template Haskell quotation 'fromWords
   |
18 |   return $ AppE (AppE (AppE (AppE (VarE 'fromWords) w1e) w2e) w3e) w4e
   |                           

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ok, in that case you should use TemplateHaskellQuotes for the GHC versions that support it, and TemplateHaskell for those that don't; this ensures that the package will keeping working with TH-less GHCs for recent GHC versions at least

Copy link
Author

Choose a reason for hiding this comment

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

Do I use the CPP and a version check for GHC > 8.0 to make the decision which to use, or is there some better way of doing it?

Copy link
Author

Choose a reason for hiding this comment

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

@hvr: ^

uuid/uuid.cabal Outdated
, entropy >= 0.3.7 && < 0.5
, network-info == 0.2.*
, random >= 1.0.1 && < 1.2
, template-haskell >= 2.7 && < 3
Copy link
Collaborator

Choose a reason for hiding this comment

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

The upper bound < 3 albeit looking cute isn't compliant w/ https://pvp.haskell.org/

@@ -79,6 +81,10 @@ import System.Random
-- <http://tools.ietf.org/html/rfc4122 RFC 4122>.
data UUID = UUID {-# UNPACK #-} !Word64 {-# UNPACK #-} !Word64
deriving (Eq, Ord, Typeable)

instance S.IsString UUID where
Copy link
Collaborator

Choose a reason for hiding this comment

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

This instance needs to be removed again

@@ -0,0 +1,30 @@
{-# LANGUAGE TemplateHaskell #-}

module Data.UUID.TH (uuid) where
Copy link
Collaborator

@hvr hvr Aug 23, 2018

Choose a reason for hiding this comment

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

Can we name this Data.UUID.QQ instead?

Can we name this Data.UUID.Quasi instead? (that way we can subsume the uuid-quasi package)

@aslatter
Copy link
Collaborator

Not sure how relevant this is, but there is a quasi-quoter over in https://hackage.haskell.org/package/uuid-quasi-0.1.0.1/docs/Data-UUID-Quasi.html

It is also relying on view patterns, however, which might be a down-side.

@hvr
Copy link
Collaborator

hvr commented Aug 23, 2018

@aslatter where do you see ViewPatterns used? And why would that be undesirable?

uuid :: QuasiQuoter
uuid = QuasiQuoter
{ quoteExp = uuidExp
, quotePat = \_ -> fail "illegal UUID QuasiQuote (allowed as expression only, used as a pattern)"
Copy link
Collaborator

Choose a reason for hiding this comment

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

We could also support patterns I think

@aslatter
Copy link
Collaborator

Sorry, I mis-remembered - the uuid-quasi package doesn't itself use ViewPatterns, but relies on ViewPatterns being enabled by the consumer if they want to use the pattern-match. If the quasi-quoter were in the uuid package itself that probably wouldn't be needed?

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.

3 participants