Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed issue where package doesn't have enough dependencies by adding a lens dependency #9

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.stack-work
*~
14 changes: 12 additions & 2 deletions ispositive.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

name: ispositive
version: 0.1
version: 0.2
cabal-version: >= 1.10
author: Christian Dietrich
maintainer: Christian Dietrich <[email protected]>
Expand All @@ -12,7 +12,7 @@ tested-with: GHC
build-type: Simple

description:
Tests whether an Integer is positive.
Tests whether a number is a positive integer.

source-repository head
type: git
Expand All @@ -21,7 +21,17 @@ source-repository head
library
build-depends:
base >= 4 && < 5
, lens
hs-source-dirs: src
default-language: Haskell2010
exposed-modules:
Integer.IsPositive

Test-Suite spec
Type: exitcode-stdio-1.0
Default-Language: Haskell2010
Hs-Source-Dirs: test
Main-Is: Spec.hs
Build-Depends: base >=4 && <5
, hspec
, ispositive
14 changes: 13 additions & 1 deletion src/Integer/IsPositive.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
module Integer.IsPositive (
is_positive_integer
, is_not_positive_integer
, positive_integer_prism
) where

is_positive_integer = (0 < )
import Control.Lens
import Control.Monad

positive_integer_prism :: RealFrac a => Prism' a a
positive_integer_prism = prism' id (mfilter p . pure)
where
p x = 1 <= x && x == fromInteger (floor x)

is_positive_integer = has positive_integer_prism

is_not_positive_integer = hasn't positive_integer_prism
35 changes: 35 additions & 0 deletions stack.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# This file was automatically generated by stack init
# For more information, see: http://docs.haskellstack.org/en/stable/yaml_configuration.html

# Specifies the GHC version and set of packages available (e.g., lts-3.5, nightly-2015-09-21, ghc-7.10.2)
resolver: lts-5.9

# Local packages, usually specified by relative directory name
packages:
- '.'
# Packages to be pulled from upstream that are not in the resolver (e.g., acme-missiles-0.3)
extra-deps: []

# Override default flag values for local packages and extra-deps
flags: {}

# Extra package databases containing global packages
extra-package-dbs: []

# Control whether we use the GHC we find on the path
# system-ghc: true

# Require a specific version of stack, using version ranges
# require-stack-version: -any # Default
# require-stack-version: >= 1.0.0

# Override the architecture used by stack, especially useful on Windows
# arch: i386
# arch: x86_64

# Extra directories used by stack for building
# extra-include-dirs: [/path/to/dir]
# extra-lib-dirs: [/path/to/dir]

# Allow a newer minor version of GHC than the snapshot specifies
# compiler-check: newer-minor
22 changes: 22 additions & 0 deletions test/Spec.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module Main where

import Integer.IsPositive
import Test.Hspec

main :: IO ()
main = hspec $ do
describe "is_positive_integer" $ do
it "-1 is not a positive integer" $
is_positive_integer (-1) `shouldBe` False

it "0 is not a positive integer" $
is_positive_integer 0 `shouldBe` False

it "1 is a positive integer" $
is_positive_integer 1 `shouldBe` True

it "0.01 is not a positive integer" $
is_positive_integer 0.01 `shouldBe` False

it "1.01 is not a positive integer" $
is_positive_integer 1.01 `shouldBe` False
1 change: 1 addition & 0 deletions test/Spec.hs~
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{-# OPTIONS_GHC -F -pgmF hspec-discover #-}