packages feed

extensible-data 0.1.0.2 → 0.1.0.3

raw patch · 3 files changed

+35/−6 lines, 3 files

Files

Data/Extensible/List.lhs view
@@ -26,6 +26,7 @@ 
 > import Control.Applicative;
 > import Control.Monad;
+> import Data.Extensible.TH__;
 > import Data.List;
 > import Language.Haskell.TH;
 
@@ -53,18 +54,28 @@ each other and contiguous.
 
 > extList :: Name -> Q Exp;
-> extList x = liftM2 (\n (ClassI _ i) -> extListInst n (ConT x) i)
->  (newName "x") (reify ''ExtList);
+> extList x = liftM2 (\n i -> extListInst n (ConT x) i)
+>  (newName "x") (thClassInstances ''ExtList);
 
-> extListInst :: Name -> Type -> [ClassInstance] -> Exp;
+> extListInst :: Name -> Type -> [[Type]] -> Exp;
 > extListInst _ _ [] = ListE [];
-> extListInst n x (ClassInstance { ci_tys = [v, p] } : t) = bool id
+> extListInst n x ([v, p] : t) = bool id
 >  (InfixE (Just e) (VarE '(++)) . Just) (v == x) (extListInst n x t)
 > where {
 >   e :: Exp;
 >   e = AppE (LamE [ConP '(,) [SigP WildP p, VarP n]] $ VarE n)
 >    (VarE 'extListContents);
 > };
+
+%> extListInst :: Name -> Type -> [ClassInstance] -> Exp;
+%> extListInst _ _ [] = ListE [];
+%> extListInst n x (ClassInstance { ci_tys = [v, p] } : t) = bool id
+%>  (InfixE (Just e) (VarE '(++)) . Just) (v == x) (extListInst n x t)
+%> where {
+%>   e :: Exp;
+%>   e = AppE (LamE [ConP '(,) [SigP WildP p, VarP n]] $ VarE n)
+%>    (VarE 'extListContents);
+%> };
 
 % End of document (final "}" is suppressed from printout)
 \medskip\centerline{The End}
+ Data/Extensible/TH__.hs view
@@ -0,0 +1,17 @@+{-# LANGUAGE CPP #-}
+{- -optP-include -optPdist/build/autogen/cabal_macros.h -}
+module Data.Extensible.TH__ (thClassInstances) where {
+  import Language.Haskell.TH;
+#if MIN_VERSION_template_haskell(2,7,0)
+    thClassInstances :: Name -> Q [[Type]];
+    thClassInstances = fmap (\(ClassI _ y) ->
+     fmap (reverse . \(InstanceD _ x _) -> t x) y) . reify where {
+      t :: Type -> [Type];
+      t (AppT x y) = y : t x;
+      t _ = [];
+    };
+#else
+    thClassInstances :: Name -> Q [[Type]];
+    thClassInstances = fmap (\(ClassI _ x) -> map ci_tys x) . reify;
+#endif
+}
extensible-data.cabal view
@@ -7,7 +7,7 @@ -- The package version. See the Haskell package versioning policy
 -- (http://www.haskell.org/haskellwiki/Package_versioning_policy) for
 -- standards guiding when and how versions should be incremented.
-Version:             0.1.0.2
+Version:             0.1.0.3
 
 -- A short (one-line) description of the package.
 Synopsis:            Sums/products/lists/trees which can be extended in other modules
@@ -49,7 +49,8 @@ Library
   -- Modules exported by the library.
   Exposed-modules:     Data.Extensible.Tree, Data.Extensible.Sum, Data.Extensible.Product, Data.Extensible.List
-  
+  Other-modules:       Data.Extensible.TH__
+
   -- Packages needed in order to build this package.
   Build-depends:
     base >= 4.3 && < 5.0,