-
Notifications
You must be signed in to change notification settings - Fork 38
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
base: master
Are you sure you want to change the base?
Conversation
1202998
to
4ff5bb7
Compare
@hvr: Can this be merged? |
@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. |
4ff5bb7
to
2c5ef6e
Compare
301745d
to
a0bce93
Compare
@hvr: By your command. |
uuid/Data/UUID/TH.hs
Outdated
@@ -0,0 +1,30 @@ | |||
{-# LANGUAGE TemplateHaskell #-} |
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.
Why do we need this extension enabled? (NB: if we enable this, uuid
stops working on TH-less GHCs)
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.
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
|
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.
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
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.
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?
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.
@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 |
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.
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 |
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.
This instance needs to be removed again
uuid/Data/UUID/TH.hs
Outdated
@@ -0,0 +1,30 @@ | |||
{-# LANGUAGE TemplateHaskell #-} | |||
|
|||
module Data.UUID.TH (uuid) where |
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.
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)
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. |
@aslatter where do you see ViewPatterns used? And why would that be undesirable? |
uuid/Data/UUID/TH.hs
Outdated
uuid :: QuasiQuoter | ||
uuid = QuasiQuoter | ||
{ quoteExp = uuidExp | ||
, quotePat = \_ -> fail "illegal UUID QuasiQuote (allowed as expression only, used as a pattern)" |
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.
We could also support patterns I think
Sorry, I mis-remembered - the |
a0bce93
to
6b8b757
Compare
6b8b757
to
9a6ce66
Compare
No description provided.