Provide a QuasiQuoter for UUID literals#41
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. |
| @@ -0,0 +1,30 @@ | |||
| {-# LANGUAGE TemplateHaskell #-} | |||
There was a problem hiding this comment.
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.
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.
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.
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?
| , 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.
The upper bound < 3 albeit looking cute isn't compliant w/ https://pvp.haskell.org/
| data UUID = UUID {-# UNPACK #-} !Word64 {-# UNPACK #-} !Word64 | ||
| deriving (Eq, Ord, Typeable) | ||
|
|
||
| instance S.IsString UUID where |
There was a problem hiding this comment.
This instance needs to be removed again
| @@ -0,0 +1,30 @@ | |||
| {-# LANGUAGE TemplateHaskell #-} | |||
|
|
|||
| module Data.UUID.TH (uuid) where | |||
There was a problem hiding this comment.
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 :: 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.
We could also support patterns I think
|
Sorry, I mis-remembered - the |
a0bce93 to
6b8b757
Compare
6b8b757 to
9a6ce66
Compare
No description provided.