मैं एक अभिव्यक्ति बनाना चाहता हूं कि मेरे पास एक संकलन त्रुटि हो या URI।संकलित समय की जांच यूआरआई
[uri|http://stackoverflow.com|]
संकलन करना चाहिए, लेकिन
[uri|foo:/bar:\|]
नहीं करना चाहिए।
मैं QuasiQuotes में आया हूं, जो स्पष्ट रूप से इस तरह की समस्या के लिए हैं। हालांकि, मैं पार्स किए गए URI
से Q Exp
बनाने के लिए प्रतीत नहीं कर सकता।
import Language.Haskell.TH.Quote
import Language.Haskell.TH.Syntax
import Language.Haskell.TH
import URI.ByteString
import Data.ByteString.Char8
uri = QuasiQuoter { quoteExp = \s ->
let
uri = either (\err -> error $ show err) id (parseURI laxURIParserOptions (pack s))
in
[| uri |]
}
संकलन नहीं करता है, क्योंकि यह URI
के लिए एक Lift
उदाहरण चाहता है। हालांकि, मुझे यकीन नहीं है कि जीएडीटी प्रकृति के कारण, एक कैसे बनाया जाए।
deriving instance Lift (URIRef a)
कोई Lift ByteString
के बारे में शिकायत करता है, लेकिन मैं विचार कोई भी लिखने के लिए की है। एक और तरीका है Data URI
होगा, लेकिन है कि
85 1 error • Couldn't match type ‘a’ with ‘Absolute’
‘a’ is a rigid type variable bound by
the instance declaration at uri-bytestring/src/URI/ByteString/Types.hs:85:1
Expected type: c (URIRef a)
Actual type: c (URIRef Absolute)
• In the expression: k (k (k (k (k (z URI)))))
In a case alternative:
ghc-prim-0.5.0.0:GHC.Types.I# 1# -> k (k (k (k (k (z URI)))))
In the expression:
case constrIndex c of {
ghc-prim-0.5.0.0:GHC.Types.I# 1# -> k (k (k (k (k (z URI)))))
_ -> k (k (k (k (z RelativeRef)))) }
When typechecking the code for ‘gunfold’
in a derived instance for ‘Data (URIRef a)’:
To see the code I am typechecking, use -ddump-deriv
• Relevant bindings include
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (URIRef a)
(bound at uri-bytestring/src/URI/ByteString/Types.hs:85:1) (haskell-stack-ghc)
के साथ विफल रहा Generics
उपयोग करने के लिए पसंद करते हैं, लेकिन मैं कैसे QQ API के साथ उन्हें इस्तेमाल करने के यकीन नहीं है।