packages feed

th-instances (empty) → 0.1.0.3

raw patch · 4 files changed

+190/−0 lines, 4 filesdep +DebugTraceHelpersdep +HUnitdep +QuickChecksetup-changed

Dependencies added: DebugTraceHelpers, HUnit, QuickCheck, base, checkers, template-haskell, test-framework, test-framework-hunit, test-framework-quickcheck2

Files

+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c)2012, Jonathan Fischoff++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 Jonathan Fischoff 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.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ src/Language/Haskell/TH/Instances.hs view
@@ -0,0 +1,90 @@+{- | A grab bag of useful instances for Template Haskell types -}+module Language.Haskell.TH.Instances where+    +import Language.Haskell.TH+import Data.String+import Test.QuickCheck+import Control.Applicative+import Test.QuickCheck.Instances.Char++instance IsString Name where+    fromString x = mkName x+    +instance Arbitrary Name where+    arbitrary = mkName <$> arbitrary+        +arb_constructor_name = do +    x <- upperAlpha+    xs <- listOf (oneof [numeric, lowerAlpha, upperAlpha])+    return $ mkName $ x:xs++instance Arbitrary Type where+    arbitrary = sized type_arb++type_arb :: Int -> Gen Type       +type_arb depth = do+        let max_option = if depth > 0 then 8 else (5 :: Int)+        typ <- choose (0, max_option)+        case typ of+            0 -> VarT <$> mkName <$> listOf lowerAlpha+            1 -> ConT <$> arb_constructor_name+            2 -> TupleT <$> arbitrary+            3 -> UnboxedTupleT <$> arbitrary +            4 -> return ArrowT+            5 -> return ListT+            6 -> forallt_arb (depth - 1)+            7 -> SigT <$> type_arb (depth - 1) <*> arbitrary+            8 -> AppT <$> type_arb (depth - 1) <*> type_arb (depth - 1)+            +--this needs work but I have no use for it now+forallt_arb :: Int -> Gen Type+forallt_arb depth = do+    ForallT <$> (return []) <*> (return []) <*> (return $ VarT $ mkName "test")+    +instance Arbitrary Kind where+    arbitrary = sized kind_arb++kind_arb :: Int -> Gen Kind        +kind_arb depth = do+    let max_option = if depth > 0 then 1 else (2 :: Int)+    typ <- choose(0, max_option)+    case typ of +        0 -> return StarK+        1 -> ArrowK <$> kind_arb (depth - 1) <*> kind_arb (depth - 1)+    +haskell_98_type_arb depth = do+    let max_option = if depth > 0 then 6 else (5 :: Int)+    typ <- choose (0, max_option)+    case typ of+        0 -> VarT <$> mkName <$> listOf lowerAlpha+        1 -> ConT <$> arb_constructor_name+        2 -> TupleT <$> arbitrary+        3 -> UnboxedTupleT <$> arbitrary +        4 -> return ArrowT+        5 -> return ListT+        6 -> AppT <$> haskell_98_type_arb (depth - 1) <*> haskell_98_type_arb (depth - 1)+        +        ++        +        ++    +    +    +    +    +    +    +    +    +    +    +    +    +    +    +    +    +    +            
+ th-instances.cabal view
@@ -0,0 +1,68 @@+-- th-instances.cabal auto-generated by cabal init. For additional+-- options, see+-- http://www.haskell.org/cabal/release/cabal-latest/doc/users-guide/authors.html#pkg-descr.+-- The name of the package.+Name:                th-instances++-- 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.3++-- A short (one-line) description of the package.+Synopsis: A place to collect orphan instances for Template Haskell++-- A longer description of the package.+Description: A IsString for name, and the beginnings of Arbitrary instances ... I have a instance for Type ... almost ... missing the ForallT.      ++-- The license under which the package is released.+License:             BSD3++-- The file containing the license text.+License-file:        LICENSE++-- The package author(s).+Author:              Jonathan Fischoff++-- An email address to which users can send suggestions, bug reports,+-- and patches.+Maintainer:          jonathangfischoff@gmail.com++-- A copyright notice.+-- Copyright:           ++Category:            Language++Build-type:          Simple++-- Extra files to be distributed with the package, such as examples or+-- a README.+-- Extra-source-files:  ++-- Constraint on the version of Cabal needed to build this package.+Cabal-version:       >=1.8+++Library+  Hs-Source-Dirs: src+  -- Modules exported by the library.+  Exposed-modules: Language.Haskell.TH.Instances+  +  -- Packages needed in order to build this package.+  Build-depends: base > 4.0.0 && <= 5.0,+                 template-haskell >= 2.6.0,+                 QuickCheck >= 2.4.1.1,+                 checkers >= 0.2.8+  ghc-options:            -Wall +  +Test-Suite tests+  Hs-Source-Dirs: src, tests+  type:       exitcode-stdio-1.0+  main-is:    Main.hs+  build-depends: base > 4.0.0 && <= 5.0,+                 DebugTraceHelpers >= 0.12,+                 test-framework-quickcheck2 >= 0.2.10,+                 test-framework-hunit >= 0.2.7,+                 test-framework >= 0.4.1.1,+                 HUnit >= 1.2.4.2+