You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I have a newtype over Scientific and I've made a quasi quoter for using it in an expression. However, I believe to make a quasi quoter to use it in a pattern context I would need access to the constructor. Would you be open to adding an Internal module that exposes the constructor for Scientific?
For reference, this is how I create Scientifics in an expression context:
instanceLiftScientificwhere
lift sci =let coefficient =Scientific.coefficient sci
base10Exponent =Scientific.base10Exponent sci
in [|Scientific.scientific $(TH.lift coefficient) $(TH.lift base10Exponent)|]
--| Arbitrary-precision value constrained to 0 through 100, inclusive.newtypePercentage=PercentageScientificderiving (Eq, Show, Read, Ord, ToJSON, Num, Fractional, Real, RealFrac, Lift)
mkPercentage::Scientific->MaybePercentage
mkPercentage sci =if sci >=0&& sci <=100thenJust (Percentage sci) elseNothing--| Create a 'Percentage' at compile time-- Usage:-- > [compilePercentage|100|]compilePercentage::QuasiQuoter
compilePercentage =QuasiQuoter
{ quoteExp = quoteExp'
, quotePat =error"percentage is not supported as a pattern"-- I don't think this can be implemented without access to the Scientific constructor. Maybe with the Num instance though?
, quoteDec =error"percentage is not supported at top-level"
, quoteType =error"percentage is not supported as a type"
}
wherequoteExp'::String->QExp
quoteExp' s =case (readMay s ::MaybeScientific) >>= mkPercentage ofNothing->fail$"Invalid Percentage: "++ s
Just percentage -> [| percentage |]
The text was updated successfully, but these errors were encountered:
Hi, I have a newtype over Scientific and I've made a quasi quoter for using it in an expression. However, I believe to make a quasi quoter to use it in a pattern context I would need access to the constructor. Would you be open to adding an
Internal
module that exposes the constructor forScientific
?For reference, this is how I create
Scientific
s in an expression context:The text was updated successfully, but these errors were encountered: