flexiwrap-smallcheck (empty) → 0.0.1
raw patch · 10 files changed
+274/−0 lines, 10 filesdep +basedep +data-typedep +flexiwrapsetup-changed
Dependencies added: base, data-type, flexiwrap, mtl, smallcheck, special-functors
Files
- .ghci +3/−0
- CHANGES +5/−0
- Data/Flex/Serial.hs +26/−0
- Data/Flex/Serial/SmallCheck/Wrap.hs +68/−0
- Data/Flex/Serial/Wrap.hs +98/−0
- LICENSE +30/−0
- README +7/−0
- Setup.hs +2/−0
- TODO +3/−0
- flexiwrap-smallcheck.cabal +32/−0
+ .ghci view
@@ -0,0 +1,3 @@+let extensions= (const . return $ let version = Data.Version.versionBranch System.Info.compilerVersion in if version < [6, 6] then ":set -fglasgow-exts -fallow-undecidable-instances -fallow-overlapping-instances" else if version >= [6, 8] then ":set -XTypeOperators -XKindSignatures" else "") :: String -> IO String +:def extensions extensions +:extensions
+ CHANGES view
@@ -0,0 +1,5 @@+== Version 0.0.1 == + +Initial version, containing support for FlexiWrap only. + +$Header: c:/Source/Haskell/Wrapper/smallcheck/RCS/CHANGES,v 1.1 2011/09/21 00:15:51 dosuser Exp dosuser $
+ Data/Flex/Serial.hs view
@@ -0,0 +1,26 @@+{-# LANGUAGE ScopedTypeVariables #-} +{-# LANGUAGE PolymorphicComponents #-} +-- .$Header: c:/Source/Haskell/Wrapper/smallcheck/Data/Flex/RCS/Serial.hs,v 1.1 2011/09/21 00:11:45 dosuser Exp dosuser $ + +-- | Utilies for implementing @'Serial'@ for flexible wrappers + +module Data.Flex.Serial ( + -- * Polymorphic function wrapper + WrapCoseries(..), + -- * Functor-like map function for (type alias) @'Series'@ + seriesMap +) where + +import Test.SmallCheck (Series) + +import Data.Flex.Utils (result) + +-- | Polymorphic function wrapper for @'coseries'@ +newtype WrapCoseries a = WrapCoseries { + unwrapCoseries :: forall b. Series b -> Series (a -> b) + } + +seriesMap :: (a -> b) -> Series a -> Series b +seriesMap = result . map + +-- vim: expandtab:tabstop=4:shiftwidth=4
+ Data/Flex/Serial/SmallCheck/Wrap.hs view
@@ -0,0 +1,68 @@+-- $Header: c:/Source/Haskell/Wrapper/smallcheck/Data/Flex/Serial/SmallCheck/RCS/Wrap.hs,v 1.1 2011/09/21 00:14:44 dosuser Exp dosuser $ + +-- | SmallCheck tests for Data.Flex.Serial.Wrap + +module Data.Flex.Serial.SmallCheck.Wrap where + +import Test.SmallCheck + +import Data.Type.TList (TNil(..), (:*:)(..)) + +import Data.Flex.Wrap (flexiWrap) +import Data.Flex.Serial.Wrap + +prop_defaultSeries_is_transparent i = wx ai == map w (x ai) + where + w = flexiWrap TNil + x = series :: Series Int + wx = series + ai = abs i + +prop_defaultCoseries_is_transparent i x = f (w x) == f x + where + ai = abs i + w = flexiWrap TNil + f :: Serial a => a -> [Int] + f y = map ($ y) $ coseries series ai + types = x :: Char + +prop_transparentSeries_is_transparent i = wx ai == map w (x ai) + where + w = flexiWrap (FWTransparentSerial :*: TNil) + x = series :: Series Char + wx = series + ai = abs i + +prop_transparentCoseries_is_transparent i x = f (w x) == f x + where + ai = abs i + w = flexiWrap (FWTransparentSerial :*: TNil) + f :: Serial a => a -> [Char] + f y = map ($ y) $ coseries series ai + types = x :: Int + +prop_explicitDefaultSeries_is_transparent i = wx ai == map w (x ai) + where + w = flexiWrap (FWDefaultSerial :*: TNil) + x = series :: Series Char + wx = series + ai = abs i + +prop_explicitDefaultCoseries_is_transparent i x = f (w x) == f x + where + ai = abs i + w = flexiWrap (FWDefaultSerial :*: TNil) + f :: Serial a => a -> [Char] + f y = map ($ y) $ coseries series ai + types = x :: Int + +testSerial :: IO () +testSerial = do + smallCheck 2 prop_defaultSeries_is_transparent + smallCheck 2 prop_defaultCoseries_is_transparent + smallCheck 2 prop_transparentSeries_is_transparent + smallCheck 2 prop_transparentCoseries_is_transparent + smallCheck 2 prop_explicitDefaultSeries_is_transparent + smallCheck 2 prop_explicitDefaultCoseries_is_transparent + +-- vim: expandtab:tabstop=4:shiftwidth=4
+ Data/Flex/Serial/Wrap.hs view
@@ -0,0 +1,98 @@+{-# LANGUAGE ScopedTypeVariables #-} +{-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies #-} +{-# LANGUAGE TypeSynonymInstances #-} +{-# LANGUAGE FlexibleInstances #-} +{-# LANGUAGE FlexibleContexts #-} +{-# LANGUAGE UndecidableInstances #-} +{-# LANGUAGE OverlappingInstances #-} +-- .$Header: c:/Source/Haskell/Wrapper/smallcheck/Data/Flex/Serial/RCS/Wrap.hs,v 1.1 2011/09/21 00:13:15 dosuser Exp dosuser $ + +-- | Instance selectors and machinery for @'Serial'@ instances for FlexiWrap + +module Data.Flex.Serial.Wrap ( + -- * Instance selectors and machinery for @'Serial'@ instances for FlexiWrap + -- ** Instance selectors + FWDefaultSerial(..), + FWTransparentSerial(..), + -- ** Machinery for @'Serial'@ instances + FWSerial, + FWSeries(..), + FWCoseries(..) +) where + +import Test.SmallCheck (Serial(..), Series) + +import Data.Type.Apply (Apply(..)) +import Data.Type.Eq (TypeCast) +import Data.Type.Proxy (Proxy(..)) +import Data.Type.TList ((:*:)) + +import Data.Flex.Serial (WrapCoseries(..), seriesMap) +import Data.Flex.Utils (result, argument) +import Data.Flex.Wrap (FlexiWrap(..), FW) + +-- Serial + +-- | Analysis class for @'Serial'@ instance selection +-- You need a specific instance of this for any instance selectors +-- you may define. +class FWSerial a r | a -> r + +-- | Instance selector type for the default (transparent) @'Serial'@ +-- instances +data FWDefaultSerial = FWDefaultSerial deriving (Show, Read) + +-- | Instance selector type for transparent @'Serial'@ instances +data FWTransparentSerial = FWTransparentSerial deriving (Show, Read) + +-- | Function identifier type for @'Apply'@. +-- You need a corresponding instance of @'Apply'@ for any +-- instance selectors you may define. +data FWSeries t a = FWSeries + +-- | Function identifier type for @'Apply'@. +-- You need a corresponding instance of @'Apply'@ for any +-- instance selectors you may define. +data FWCoseries t a = FWCoseries + +-- | * Default instance +instance TypeCast r FWTransparentSerial => FWSerial (FW t a) r + +-- | * Propagated instance +instance FWSerial (FW s a) r => FWSerial (FW (x :*: s) a) r + +-- | * Specific @'FWDefaultSerial'@ instance +instance FWSerial (FW (FWDefaultSerial :*: s) a) FWTransparentSerial + +-- | * Specific @'FWTransparentSerial'@ instance +instance FWSerial (FW (FWTransparentSerial :*: s) a) + FWTransparentSerial + +-- | ** Implementation instance for @'Serial'@ instance selection +instance Serial a => + Apply (Proxy (FWSeries t a)) (Proxy FWTransparentSerial) + (Series (FW t a)) + where + apply _ _ = seriesMap FlexiWrap series + +-- | ** Implementation instance for @'Serial'@ instance selection +instance Serial a => + Apply (Proxy (FWCoseries t a)) (Proxy FWTransparentSerial) + (WrapCoseries (FW t a)) + where + apply _ _ = + WrapCoseries ((result . seriesMap . argument) unFlexiWrap coseries) + +-- | * Coordinating instance of @'Serial'@ +instance forall t a r. ( + Apply (Proxy (FWSeries t a)) (Proxy r) (Series (FW t a)), + Apply (Proxy (FWCoseries t a)) (Proxy r) + (WrapCoseries (FW t a)), + FWSerial (FW t a) r + ) => + Serial (FW t a) where + series = apply (Proxy :: Proxy (FWSeries t a)) (Proxy :: Proxy r) + coseries = unwrapCoseries $ + apply (Proxy :: Proxy (FWCoseries t a)) (Proxy :: Proxy r) + +-- vim: expandtab:tabstop=4:shiftwidth=4
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright Iain Alexander 2011. +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + + * Neither the name of Iain Alexander nor the names of other + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ README view
@@ -0,0 +1,7 @@+Readme for flexiwrap-smallcheck version 0.0.1 + +This package contains material for the flexiwrap package which +also requires the smallcheck package, i.e. support for the +Serial typeclass. + +$Header: c:/Source/Haskell/Wrapper/smallcheck/RCS/README,v 1.1 2011/09/21 00:17:21 dosuser Exp dosuser $
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple +main = defaultMain
+ TODO view
@@ -0,0 +1,3 @@+Add instances for FlexiWrapT and FlexiWrapCTC. + +$Header: c:/Source/Haskell/Wrapper/smallcheck/RCS/TODO,v 1.1 2011/09/21 00:17:43 dosuser Exp dosuser $
+ flexiwrap-smallcheck.cabal view
@@ -0,0 +1,32 @@+Name: flexiwrap-smallcheck +Version: 0.0.1 +Cabal-version: >= 1.2.3 +Build-Type: Simple +Synopsis: SmallCheck (Serial) instances for flexiwrap +Description: SmallCheck (Serial) instances for flexiwrap +Category: Data +License: BSD3 +License-File: LICENSE +Author: Iain Alexander <ia@stryx.demon.co.uk> +Maintainer: Iain Alexander <ia@stryx.demon.co.uk> +Build-Type: Simple +Extra-source-files: .ghci + , Data/Flex/Serial/SmallCheck/Wrap.hs + , README + , CHANGES + , TODO +Tested-with: GHC==6.4.1, GHC==6.6.1, GHC==6.8.3, GHC==6.10.4, GHC==6.12.3 + , GHC==7.0.1, GHC==7.0.4 +Library + Exposed-Modules: Data.Flex.Serial + , Data.Flex.Serial.Wrap + if impl(ghc < 6.6.1) + Extensions: UndecidableInstances + Build-Depends: special-functors < 2 + if impl(ghc < 6.8.1) + Ghc-options: -fglasgow-exts + if impl(ghc >= 6.8.1) + Extensions: TypeOperators, KindSignatures + Build-Depends: base < 5, data-type >= 0.1 && < 0.2, mtl < 2.1 + , flexiwrap < 0.2, smallcheck >= 0.4 +-- vim: expandtab:tabstop=4:shiftwidth=4