packages feed

primes-type 0.2.0.1 → 0.2.0.2

raw patch · 3 files changed

+48/−1 lines, 3 filesdep +criteriondep +deepseqdep ~base

Dependencies added: criterion, deepseq

Dependency ranges changed: base

Files

+ bench/Bench.hs view
@@ -0,0 +1,24 @@+module Main where++import Criterion+import Criterion.Main++import Data.Numbers.Primes.Type++n = 2 ^ 16+p :: Prime Int+p = getPrime n++main = defaultMain+        [ env (return p) benchPrimes+        ]++benchPrimes p = bgroup "Some benchmarks"+    [ bench "getValue"      $ nf getValue p+    , bench "getIndex"      $ nf getIndex p+    , bench "deconstruct"   $ nf deconstruct p+    , bench "primeIndex"    $ nf primeIndex (getValue p)+    , bench "getPrime"      $ nf (getPrime :: Int -> Prime Int) n+    , bench "maybePrime"    $ nf maybePrime (getValue p)+    , bench "indexedPrimes" $ nf (flip take (indexedPrimes :: [Prime Int])) n+    ]
primes-type.cabal view
@@ -3,7 +3,7 @@ -- see: https://github.com/sol/hpack  name:           primes-type-version:        0.2.0.1+version:        0.2.0.2 synopsis:       Type-safe prime numbers. description:    This library provides type safe prime numbers. The idea is based upon the concept of a predicate type from type theory. category:       Algorithms, Numerical@@ -27,6 +27,7 @@   build-depends:       base >=4.8 && <4.11     , primes >=0.2 && <0.3+    , deepseq   exposed-modules:       Data.Numbers.Primes.Type   other-modules:@@ -44,4 +45,17 @@     , primes >=0.2 && <0.3     , primes-type     , HTF >=0.13 && < 0.14+  default-language: Haskell2010++benchmark primes-type-bench+  type: exitcode-stdio-1.0+  main-is: Bench.hs+  hs-source-dirs:+      bench+  ghc-options: -threaded -rtsopts -with-rtsopts=-N+  build-depends:+      base >=4.8 && <5+    , primes >=0.2 && <0.3+    , primes-type+    , criterion   default-language: Haskell2010
src/Data/Numbers/Primes/Type.hs view
@@ -1,4 +1,6 @@ {-# OPTIONS_GHC -funbox-strict-fields #-}+{-# LANGUAGE StandaloneDeriving #-}+{-# LANGUAGE DeriveGeneric #-}  module Data.Numbers.Primes.Type     ( Prime@@ -13,6 +15,8 @@  import Data.List (elemIndex) import Data.Numbers.Primes+import GHC.Generics+import Control.DeepSeq  -- | An abstract type for primes. --@@ -40,6 +44,11 @@  instance Ord (Prime int) where     x `compare` y = getIndex x `compare` getIndex y++deriving instance Generic (Prime a)+deriving instance Generic1 Prime+instance NFData a => NFData (Prime a)+instance NFData1 Prime  -- | If a given number is prime, give back its index. primeIndex :: Integral n => n -> Maybe Int