d10 0.1.0.1 → 0.1.1.0
raw patch · 4 files changed
+151/−12 lines, 4 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Data.D10.Char: d10Exp :: Integral a => a -> Q Exp
+ Data.D10.Char: d10ListExp :: String -> Q Exp
+ Data.D10.Num: d10Exp :: forall a b. (Integral b, Lift a, Num a) => b -> Q Exp
+ Data.D10.Num: d10ListExp :: forall a. (Lift a, Num a) => String -> Q Exp
+ Data.D10.Safe: d10Exp :: Integral a => a -> Q Exp
+ Data.D10.Safe: d10ListExp :: String -> Q Exp
Files
- d10.cabal +1/−1
- src/Data/D10/Char.hs +49/−4
- src/Data/D10/Num.hs +53/−4
- src/Data/D10/Safe.hs +48/−3
d10.cabal view
@@ -1,5 +1,5 @@ name: d10-version: 0.1.0.1+version: 0.1.1.0 category: Data synopsis: Digits 0-9
src/Data/D10/Char.hs view
@@ -1,6 +1,6 @@-{-# LANGUAGE DeriveLift #-}-{-# LANGUAGE InstanceSigs #-}-{-# LANGUAGE TemplateHaskell #-}+{-# LANGUAGE DeriveLift #-}+{-# LANGUAGE InstanceSigs #-}+{-# LANGUAGE TypeApplications #-} -- | Defines a 'D10' type as a newtype for 'Char', where the -- values are restricted to characters between @'0'@ and @'9'@.@@ -16,6 +16,10 @@ , d10 , d10list + -- * Splice expressions+ , d10Exp+ , d10ListExp+ -- * Converting between D10 and Char , d10Char , charD10Maybe@@ -76,12 +80,13 @@ import Prelude hiding (fail) -- template-haskell-import Language.Haskell.TH (ExpQ, Q)+import Language.Haskell.TH (Exp, Q) import Language.Haskell.TH.Quote (QuasiQuoter (..)) import Language.Haskell.TH.Syntax (Lift (lift)) -- $setup -- >>> :set -XQuasiQuotes+-- >>> :set -XTemplateHaskell --------------------------------------------------- @@ -690,6 +695,46 @@ integralD10Fail :: (Integral a, MonadFail m) => a -> m D10 integralD10Fail x = integerD10Fail (toInteger x)++---------------------------------------------------++-- | A single base-10 digit.+--+-- Produces an expression of type 'D10' that can be used+-- in a Template Haskell splice.+--+-- >>> d10Nat $(d10Exp 5)+-- 5+--+-- >>> d10Nat $(d10Exp 12)+-- ...+-- ... d10 must be between 0 and 9+-- ...++d10Exp :: Integral a => a -> Q Exp+d10Exp = integralD10Fail >=> lift @D10++-- | A list of base-10 digits.+--+-- Produces an expression of type @['D10']@ that can be used+-- in a Template Haskell splice.+--+-- >>> d10Nat <$> $(d10ListExp "")+-- []+--+-- >>> d10Nat <$> $(d10ListExp "5")+-- [5]+--+-- >>> d10Nat <$> $(d10ListExp "58")+-- [5,8]+--+-- >>> d10Nat <$> $(d10ListExp "a")+-- ...+-- ... d10 must be between 0 and 9+-- ...++d10ListExp :: String -> Q Exp+d10ListExp = strD10ListFail >=> lift @[D10] ---------------------------------------------------
src/Data/D10/Num.hs view
@@ -2,7 +2,6 @@ {-# LANGUAGE DeriveLift #-} {-# LANGUAGE InstanceSigs #-} {-# LANGUAGE ScopedTypeVariables #-}-{-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE TypeApplications #-} -- | Defines a 'D10' type as a newtype for any type with an@@ -20,6 +19,10 @@ , d10 , d10list + -- * Splice expressions+ , d10Exp+ , d10ListExp+ -- * Converting between D10 and Char , d10Char , charD10Maybe@@ -80,12 +83,13 @@ import Prelude hiding (fail) -- template-haskell-import Language.Haskell.TH (ExpQ, Q)+import Language.Haskell.TH (Exp, Q) import Language.Haskell.TH.Quote (QuasiQuoter (..)) import Language.Haskell.TH.Syntax (Lift (lift)) -- $setup -- >>> :set -XQuasiQuotes+-- >>> :set -XTemplateHaskell --------------------------------------------------- @@ -98,8 +102,13 @@ -- * @'integerD10Maybe' :: 'Integer' -> 'Maybe' 'D10'@ -- * @'integerMod10' :: 'Integer' -> 'D10'@ ----- With the @QuasiQuotes@ GHC extension enabled, you can write--- 'D10' literals using the quasi-quoters 'd10' and 'd10list'.+-- There are also several ways to safely write 'D10' literals+-- using Template Haskell:+--+-- * With the @QuasiQuotes@ GHC extension enabled, you can write+-- use the quasi-quoters 'd10' and 'd10list'.+-- * With the @TemplateHaskell@ GHC extension enabled, you can+-- splice expressions produced by 'd10Exp' and 'd10ListExp'. newtype D10 a = D10_Unsafe a@@ -693,6 +702,46 @@ integralD10Fail :: (Num b, Integral a, MonadFail m) => a -> m (D10 b) integralD10Fail x = integerD10Fail (toInteger x)++---------------------------------------------------++-- | A single base-10 digit.+--+-- Produces an expression of type @'D10' a@ that can be used+-- in a Template Haskell splice.+--+-- >>> d10Nat $(d10Exp 5)+-- 5+--+-- >>> d10Nat $(d10Exp 12)+-- ...+-- ... d10 must be between 0 and 9+-- ...++d10Exp :: forall a b. (Integral b, Lift a, Num a) => b -> Q Exp+d10Exp = integralD10Fail >=> lift @(D10 a)++-- | A list of base-10 digits.+--+-- Produces an expression of type @['D10' a]@ that can be used+-- in a Template Haskell splice.+--+-- >>> d10Nat <$> $(d10ListExp "")+-- []+--+-- >>> d10Nat <$> $(d10ListExp "5")+-- [5]+--+-- >>> d10Nat <$> $(d10ListExp "58")+-- [5,8]+--+-- >>> d10Nat <$> $(d10ListExp "a")+-- ...+-- ... d10 must be between 0 and 9+-- ...++d10ListExp :: forall a. (Lift a, Num a) => String -> Q Exp+d10ListExp = strD10ListFail >=> lift @[D10 a] ---------------------------------------------------
src/Data/D10/Safe.hs view
@@ -1,5 +1,5 @@-{-# LANGUAGE DeriveLift #-}-{-# LANGUAGE TemplateHaskell #-}+{-# LANGUAGE DeriveLift #-}+{-# LANGUAGE TypeApplications #-} -- | Defines a 'D10' type as -- @'D0' | 'D1' | 'D2' | 'D3' | 'D4' | 'D5' | 'D6' | 'D7' | 'D8' | 'D9'@.@@ -21,6 +21,10 @@ , d10 , d10list + -- * Splice expressions+ , d10Exp+ , d10ListExp+ -- * Converting between D10 and Char , d10Char , charD10Maybe@@ -80,12 +84,13 @@ import Prelude hiding (fail) -- template-haskell-import Language.Haskell.TH (ExpQ, Q)+import Language.Haskell.TH (Exp, Q) import Language.Haskell.TH.Quote (QuasiQuoter (..)) import Language.Haskell.TH.Syntax (Lift (lift)) -- $setup -- >>> :set -XQuasiQuotes+-- >>> :set -XTemplateHaskell --------------------------------------------------- @@ -727,6 +732,46 @@ case (integralD10Maybe x) of Just y -> return y Nothing -> fail "d10 must be between 0 and 9"++---------------------------------------------------++-- | A single base-10 digit.+--+-- Produces an expression of type 'D10' that can be used+-- in a Template Haskell splice.+--+-- >>> $(d10Exp 5)+-- D5+--+-- >>> $(d10Exp 12)+-- ...+-- ... d10 must be between 0 and 9+-- ...++d10Exp :: Integral a => a -> Q Exp+d10Exp = integralD10Fail >=> lift @D10++-- | A list of base-10 digits.+--+-- Produces an expression of type @['D10']@ that can be used+-- in a Template Haskell splice.+--+-- >>> $(d10ListExp "")+-- []+--+-- >>> $(d10ListExp "5")+-- [D5]+--+-- >>> $(d10ListExp "58")+-- [D5,D8]+--+-- >>> $(d10ListExp "a")+-- ...+-- ... d10 must be between 0 and 9+-- ...++d10ListExp :: String -> Q Exp+d10ListExp = strD10ListFail >=> lift @[D10] ---------------------------------------------------