packages feed

product-isomorphic 0.0.2.0 → 0.0.3.0

raw patch · 6 files changed

+68/−19 lines, 6 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

+ Data.Functor.ProductIsomorphic.GenericInstances: instance Data.Functor.ProductIsomorphic.Unsafe.ProductConstructor (GHC.Generics.U1 p)
+ Data.Functor.ProductIsomorphic.GenericInstances: instance Data.Functor.ProductIsomorphic.Unsafe.ProductConstructor (c -> GHC.Generics.K1 i c p)
+ Data.Functor.ProductIsomorphic.GenericInstances: instance Data.Functor.ProductIsomorphic.Unsafe.ProductConstructor (f p -> GHC.Generics.M1 i c f p)
+ Data.Functor.ProductIsomorphic.GenericInstances: instance Data.Functor.ProductIsomorphic.Unsafe.ProductConstructor (f x -> g x -> (GHC.Generics.:*:) f g x)
- Data.Functor.ProductIsomorphic.TH: reifyRecordType :: Name -> Q ((TypeQ, ExpQ), (Maybe [Name], [TypeQ]))
+ Data.Functor.ProductIsomorphic.TH: reifyRecordType :: Name -> Q (((TypeQ, [Name]), ExpQ), (Maybe [Name], [TypeQ]))

Files

product-isomorphic.cabal view
@@ -1,5 +1,5 @@ name:                product-isomorphic-version:             0.0.2.0+version:             0.0.3.0 synopsis:            Weaken applicative functor on products description:         Weaken applicative functor which allows only product                      construction. Product constructions and deconstructions@@ -26,6 +26,7 @@                      Data.Functor.ProductIsomorphic.Class                      Data.Functor.ProductIsomorphic.Instances                      Data.Functor.ProductIsomorphic.TupleInstances+                     Data.Functor.ProductIsomorphic.GenericInstances                      Data.Functor.ProductIsomorphic.Unsafe                      Data.Functor.ProductIsomorphic 
src/Data/Functor/ProductIsomorphic.hs view
@@ -8,13 +8,14 @@ -- Portability : unknown -- -- This is the integrated interface module for product restricted functors.-module Data.Functor.ProductIsomorphic-       ( module Data.Functor.ProductIsomorphic.Unsafe-       , module Data.Functor.ProductIsomorphic.Class-       , module Data.Functor.ProductIsomorphic.Instances-       ) where+module Data.Functor.ProductIsomorphic (+  module Data.Functor.ProductIsomorphic.Unsafe,+  module Data.Functor.ProductIsomorphic.Class,+  module Data.Functor.ProductIsomorphic.Instances,+  ) where  import Data.Functor.ProductIsomorphic.Unsafe (ProductConstructor) import Data.Functor.ProductIsomorphic.Class import Data.Functor.ProductIsomorphic.Instances import Data.Functor.ProductIsomorphic.TupleInstances ()+import Data.Functor.ProductIsomorphic.GenericInstances ()
+ src/Data/Functor/ProductIsomorphic/GenericInstances.hs view
@@ -0,0 +1,46 @@+{-# OPTIONS_GHC -fno-warn-orphans #-}+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE TypeOperators #-}++-- |+-- Module      : Data.Functor.ProductIsomorphic.GenericInstances+-- Copyright   : 2017 Kei Hibino+-- License     : BSD3+--+-- Maintainer  : ex8k.hibino@gmail.com+-- Stability   : experimental+-- Portability : unknown+--+-- This module defines instances for constructors used in generic-programming.+module Data.Functor.ProductIsomorphic.GenericInstances () where++import GHC.Generics+  (U1 (U1), K1 (K1), M1 (M1), (:*:) ((:*:)), )+-- import GHC.Generics (Generic, Rep, from, to, )++import Data.Functor.ProductIsomorphic.Unsafe (ProductConstructor (..))+++instance ProductConstructor (U1 p) where+  productConstructor = U1+  {-# INLINEABLE productConstructor #-}++instance ProductConstructor (c -> K1 i c p) where+  productConstructor = K1+  {-# INLINEABLE productConstructor #-}++instance ProductConstructor (f p -> M1 i c f p) where+  productConstructor = M1+  {-# INLINEABLE productConstructor #-}++instance ProductConstructor (f x -> g x -> (f :*: g) x) where+  productConstructor = (:*:)+  {-# INLINEABLE productConstructor #-}++{- -- why compile error?+instance Generic a => ProductConstructor (a -> Rep a x) where+  productConstructor = from++instance Generic a => ProductConstructor (Rep a x -> a) where+  productConstructor = to+ -}
src/Data/Functor/ProductIsomorphic/Instances.hs view
@@ -12,10 +12,10 @@ -- -- This module defines functor instances morphed functions -- are restricted to products.-module Data.Functor.ProductIsomorphic.Instances-       ( WrappedFunctor (..)-       , WrappedAlter (..)-       ) where+module Data.Functor.ProductIsomorphic.Instances (+  WrappedFunctor (..),+  WrappedAlter (..),+  ) where  import Data.Monoid (Monoid, mempty, (<>)) import Control.Applicative
src/Data/Functor/ProductIsomorphic/TH/Internal.hs view
@@ -27,22 +27,23 @@ import Data.Functor.ProductIsomorphic.Unsafe (ProductConstructor (..))  -recordInfo' :: Info -> Maybe ((TypeQ, ExpQ), (Maybe [Name], [TypeQ]))+recordInfo' :: Info -> Maybe (((TypeQ, [Name]), ExpQ), (Maybe [Name], [TypeQ])) recordInfo' =  d  where   d (TyConI tcon) = do     (_cxt, tcn, bs, _mk, [r], _ds) <- unDataD tcon+    let vns = map getTV bs     case r of-      NormalC dcn ts   -> Just ((buildT tcn bs, conE dcn), (Nothing, [return t | (_, t) <- ts]))-      RecC    dcn vts  -> Just ((buildT tcn bs, conE dcn), (Just ns, ts))+      NormalC dcn ts   -> Just (((buildT tcn vns, vns), conE dcn), (Nothing, [return t | (_, t) <- ts]))+      RecC    dcn vts  -> Just (((buildT tcn vns, vns), conE dcn), (Just ns, ts))         where (ns, ts) = unzip [(n, return t) | (n, _, t) <- vts]       _                -> Nothing   d _                  =  Nothing   getTV (PlainTV n)    =  n   getTV (KindedTV n _) =  n-  buildT tcn bs = foldl' appT (conT tcn) [ varT $ getTV b | b <- bs]+  buildT tcn vns = foldl' appT (conT tcn) [ varT vn | vn <- vns ]  -- | Low-level reify interface for record type name.-reifyRecordType :: Name -> Q ((TypeQ, ExpQ), (Maybe [Name], [TypeQ]))+reifyRecordType :: Name -> Q (((TypeQ, [Name]), ExpQ), (Maybe [Name], [TypeQ])) reifyRecordType recTypeName =   maybe   (fail $ "Defined record type constructor not found: " ++ show recTypeName)@@ -53,7 +54,7 @@ defineProductConstructor :: Name     -- ^ name of product or record type constructor                          -> Q [Dec]  -- ^ result template defineProductConstructor tyN = do-  ((tyQ, dtQ), (_, colts))  <- reifyRecordType tyN+  (((tyQ, _), dtQ), (_, colts))  <- reifyRecordType tyN   [d| instance ProductConstructor $(foldr (appT . (arrowT `appT`)) tyQ colts) where         productConstructor = $(dtQ)     |]
src/Data/Functor/ProductIsomorphic/Unsafe.hs view
@@ -8,9 +8,9 @@ -- Portability : unknown -- -- This module defines unsafe class interfaces.-module Data.Functor.ProductIsomorphic.Unsafe-       ( ProductConstructor (..)-       ) where+module Data.Functor.ProductIsomorphic.Unsafe (+  ProductConstructor (..),+  ) where  -- | Define product isomorphic inference rule --   to specify record constructor