packages feed

vector-th-unbox 0.1.0.2 → 0.2

raw patch · 2 files changed

+23/−28 lines, 2 filesdep ~vectorPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: vector

API changes (from Hackage documentation)

- Data.Vector.Unboxed.Deriving: class Unbox' src rep
- Data.Vector.Unboxed.Deriving: derivingUnbox :: String -> DecsQ -> ExpQ -> ExpQ -> DecsQ
+ Data.Vector.Unboxed.Deriving: derivingUnbox :: String -> TypeQ -> ExpQ -> ExpQ -> DecsQ

Files

Data/Vector/Unboxed/Deriving.hs view
@@ -25,18 +25,16 @@ succinctly:  >derivingUnbox "Complex"->    [d| instance (Unbox a) => Unbox' (Complex a) (a, a) |]->    [| \ (r :+ i) -> (r, i) |]->    [| \ (r, i) -> r :+ i |]+>    [d| (Unbox a) ⇒ Complex a → (a, a) |]+>    [| \ (r :+ i) → (r, i) |]+>    [| \ (r, i) → r :+ i |] -Requires the @MultiParamTypeClasses@, @TemplateHaskell@ and @TypeFamilies@-@LANGUAGE@ extensions.+Requires the @MultiParamTypeClasses@, @TemplateHaskell@, @TypeFamilies@ and+probably the @FlexibleInstances@ @LANGUAGE@ extensions.  -} -module Data.Vector.Unboxed.Deriving-    ( Unbox', derivingUnbox-    ) where+module Data.Vector.Unboxed.Deriving (derivingUnbox) where  import Control.Arrow import Control.Applicative@@ -46,29 +44,24 @@ import Data.Vector.Unboxed.Base (MVector (..), Vector (..), Unbox) import Language.Haskell.TH --- | A dummy class providing a convenient way to pass in the source and--- representation types, along with any requisite constraints and (implicit)--- type variable introductions.-class Unbox' src rep- -- Create a @Pat@ bound to the given name and an @Exp@ for said binding. newPatExp :: String -> Q (Pat, Exp) newPatExp = fmap (VarP &&& VarE) . newName  -- Create a wrapper for the given function with the same 'nameBase', given -- a list of argument bindings and expressions in terms of said bindings.--- A final coercion (@Exp -> Exp@) is applied to the body of the function.+-- A final coercion (@Exp → Exp@) is applied to the body of the function. -- Complimentary @INLINE@ pragma included. wrap :: Name -> [(Pat, Exp)] -> (Exp -> Exp) -> [Dec] wrap fun (unzip -> (pats, exps)) coerce = [inline, method] where-    base = mkName (nameBase fun) #if MIN_VERSION_template_haskell(2,8,0)-    inline = PragmaD (InlineP base Inline FunLike AllPhases)+    inline = PragmaD (InlineP fun Inline FunLike AllPhases) #else-    inline = PragmaD (InlineP base (InlineSpec True False Nothing))+    inline = PragmaD ( InlineP (mkName (nameBase fun))+        (InlineSpec True False Nothing) ) #endif     body = coerce $ foldl AppE (VarE fun) exps-    method = FunD base [Clause pats (NormalB body) []]+    method = FunD fun [Clause pats (NormalB body) []]  {-| Let's consider a more complex example: suppose we want an @Unbox@ instance for @Maybe a@. We can encode this using the pair @(Bool, a)@, with@@ -77,24 +70,26 @@ additional @Default@ (see the @data-default@ package) constraint. Thus:  >derivingUnbox "Maybe"->    [d| instance (Default a, Unbox a) => Unbox' (Maybe a) (Bool, a) |]->    [| maybe (False, def) (\ x -> (True, x)) |]->    [| \ (b, x) -> if b then Just x else Nothing |]+>    [d| (Default a, Unbox a) ⇒ Maybe a → (Bool, a) |]+>    [| maybe (False, def) (\ x → (True, x)) |]+>    [| \ (b, x) → if b then Just x else Nothing |] -} derivingUnbox     :: String   -- ^ Unique constructor suffix for the MVector and Vector data families-    -> DecsQ    -- ^ Quotation of the form @[d| instance /ctxt/ => Unbox' src rep |]@-    -> ExpQ     -- ^ Quotation of an expression of type @src -> rep@-    -> ExpQ     -- ^ Quotation of an expression of type @rep -> src@+    -> TypeQ    -- ^ Quotation of the form @[t| /ctxt/ ⇒ src → rep |]@+    -> ExpQ     -- ^ Quotation of an expression of type @src → rep@+    -> ExpQ     -- ^ Quotation of an expression of type @rep → src@     -> DecsQ    -- ^ Declarations to be spliced for the derived Unbox instance derivingUnbox name argsQ toRepQ fromRepQ = do     let mvName = mkName ("MV_" ++ name)     let vName  = mkName ("V_" ++ name)     toRep <- toRepQ     fromRep <- fromRepQ-    -- fail unless argsQ quotes a single Unbox' instance-    [ InstanceD cxts (ConT (nameBase -> "Unbox'")-        `AppT` typ `AppT` rep) [] ] <- argsQ+    args <- argsQ+    (cxts, typ, rep) <- case args of+        ForallT _ cxts (ArrowT `AppT` typ `AppT` rep) -> return (cxts, typ, rep)+        ArrowT `AppT` typ `AppT` rep -> return ([], typ, rep)+        _ -> fail "Expecting a type of the form: cxts => typ -> rep"      let liftE e = InfixE (Just e) (VarE 'liftM) . Just     let mvCon = ConE mvName
vector-th-unbox.cabal view
@@ -1,5 +1,5 @@ name:           vector-th-unbox-version:        0.1.0.2+version:        0.2 synopsis:       Deriver for Data.Vector.Unboxed using Template Haskell description:     A Template Haskell deriver for unboxed vectors, given a pair of coercion