Skip to content

Provide a QuasiQuoter for UUID literals#41

Open
jessekempf wants to merge 1 commit into
haskell-hvr:masterfrom
jessekempf:add_isstring
Open

Provide a QuasiQuoter for UUID literals#41
jessekempf wants to merge 1 commit into
haskell-hvr:masterfrom
jessekempf:add_isstring

Conversation

@jessekempf

Copy link
Copy Markdown

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
Copy Markdown
Author

@hvr: Can this be merged?

@hvr

hvr commented Aug 18, 2018

Copy link
Copy Markdown
Collaborator

@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
Copy Markdown
Author

@hvr: By your command.

Comment thread uuid/Data/UUID/TH.hs
@@ -0,0 +1,30 @@
{-# LANGUAGE TemplateHaskell #-}

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Author

Choose a reason for hiding this comment

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

@hvr: ^

Comment thread 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
Copy Markdown
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/

Comment thread uuid-types/Data/UUID/Types/Internal.hs Outdated
data UUID = UUID {-# UNPACK #-} !Word64 {-# UNPACK #-} !Word64
deriving (Eq, Ord, Typeable)

instance S.IsString UUID where

Copy link
Copy Markdown
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

Comment thread uuid/Data/UUID/TH.hs Outdated
@@ -0,0 +1,30 @@
{-# LANGUAGE TemplateHaskell #-}

module Data.UUID.TH (uuid) where

@hvr hvr Aug 23, 2018

Copy link
Copy Markdown
Collaborator

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
Copy Markdown
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

hvr commented Aug 23, 2018

Copy link
Copy Markdown
Collaborator

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

Comment thread uuid/Data/UUID/TH.hs
uuid :: QuasiQuoter
uuid = QuasiQuoter
{ quoteExp = uuidExp
, quotePat = \_ -> fail "illegal UUID QuasiQuote (allowed as expression only, used as a pattern)"

Copy link
Copy Markdown
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
Copy Markdown
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