]> git.rkrishnan.org Git - functorrent.git/commitdiff
Move Arbitrary instances into another module
authorRamakrishnan Muthukrishnan <ram@rkrishnan.org>
Mon, 27 Apr 2015 12:31:18 +0000 (18:01 +0530)
committerRamakrishnan Muthukrishnan <ram@rkrishnan.org>
Mon, 27 Apr 2015 12:31:18 +0000 (18:01 +0530)
Suppress the orphan instance warning.

functorrent.cabal
src/FuncTorrent/Bencode.hs
src/TestInstances.hs [new file with mode: 0644]

index 05ed4b3aa8286c403b2611126c15195f007636e6..0251a3c8910d91bd2cc38d2c7d372ba967817a94 100644 (file)
@@ -39,15 +39,15 @@ library
                        HTTP,
                        network-uri,
                        parsec,
-                       QuickCheck,
                        tasty,
                        tasty-hunit
 
 executable functorrent
   main-is:             Main.hs
+  other-modules:       TestInstances
   other-extensions:    OverloadedStrings
   hs-source-dirs:      src
-  ghc-options:         -Wall -fwarn-incomplete-patterns -optc-Os
+  ghc-options:         -Wall -fwarn-incomplete-patterns -fno-warn-orphans -optc-Os
   default-language:    Haskell2010
   build-depends:       base,
                        base16-bytestring,
index 62d476733530ad650d6a293f5255d3c6c26ba147..3a982ec0336da0f8ca5a31bbfb73ed4a29b2d78e 100644 (file)
@@ -19,7 +19,6 @@ import Data.Functor ((<$>))
 import Data.Map.Strict (Map, fromList, toList)
 import Text.ParserCombinators.Parsec
 import qualified Text.Parsec.ByteString as ParsecBS
-import Test.QuickCheck
 
 data BVal = Bint Integer
           | Bstr ByteString
@@ -27,22 +26,6 @@ data BVal = Bint Integer
           | Bdict (Map String BVal)
             deriving (Ord, Eq, Show)
 
-instance Arbitrary ByteString where
-  arbitrary = pack <$> arbitrary
-
-instance Arbitrary BVal where
-  arbitrary = sized bval
-              where
-                bval :: Int -> Gen BVal
-                bval 0 = oneof [ Bint <$> arbitrary
-                               , Bstr <$> arbitrary]
-                bval n = oneof [ Bint <$> arbitrary
-                               , Bstr <$> arbitrary
-                               , Blist <$> vectorOf n (bval (n `div` 4))
-                               , do keys <- vectorOf n arbitrary
-                                    vals <- vectorOf n (bval (n `div` 4))
-                                    return $ Bdict $ fromList $ zip keys vals ]
-
 -- getters
 bValToInteger :: BVal -> Maybe Integer
 bValToInteger (Bint x) = Just x
diff --git a/src/TestInstances.hs b/src/TestInstances.hs
new file mode 100644 (file)
index 0000000..4d9082c
--- /dev/null
@@ -0,0 +1,22 @@
+module FuncTorrent.TestInstances where
+
+import qualified Data.ByteString as B
+import Test.QuickCheck
+
+import Bencode
+
+instance Arbitrary B.ByteString where
+  arbitrary = B.pack <$> arbitrary
+
+instance Arbitrary BVal where
+  arbitrary = sized bval
+              where
+                bval :: Int -> Gen BVal
+                bval 0 = oneof [ Bint <$> arbitrary
+                               , Bstr <$> arbitrary]
+                bval n = oneof [ Bint <$> arbitrary
+                               , Bstr <$> arbitrary
+                               , Blist <$> vectorOf n (bval (n `div` 4))
+                               , do keys <- vectorOf n arbitrary
+                                    vals <- vectorOf n (bval (n `div` 4))
+                                    return $ Bdict $ fromList $ zip keys vals ]