packages feed

dollaridoos (empty) → 0.1.0.0

raw patch · 8 files changed

+314/−0 lines, 8 filesdep +basedep +profunctorsdep +semigroupssetup-changed

Dependencies added: base, profunctors, semigroups

Files

+ .gitignore view
@@ -0,0 +1,16 @@+dist+cabal-dev+*.o+*.hi+*.chi+*.chs.h+*.dyn_o+*.dyn_hi+.hpc+.hsenv+.cabal-sandbox/+cabal.sandbox.config+*.prof+*.aux+*.hp+*.swp
+ .travis.yml view
@@ -0,0 +1,103 @@+# This Travis job script has been generated by a script via+#+#   make_travis_yml_2.hs 'dollaridoos.cabal'+#+# For more information, see https://github.com/hvr/multi-ghc-travis+#+language: c+sudo: false++git:+  submodules: false  # whether to recursively clone submodules++cache:+  directories:+    - $HOME/.cabal/packages+    - $HOME/.cabal/store++before_cache:+  - rm -fv $HOME/.cabal/packages/hackage.haskell.org/build-reports.log+  # remove files that are regenerated by 'cabal update'+  - rm -fv $HOME/.cabal/packages/hackage.haskell.org/00-index.*+  - rm -fv $HOME/.cabal/packages/hackage.haskell.org/*.json+  - rm -fv $HOME/.cabal/packages/hackage.haskell.org/01-index.cache+  - rm -fv $HOME/.cabal/packages/hackage.haskell.org/01-index.tar+  - rm -fv $HOME/.cabal/packages/hackage.haskell.org/01-index.tar.idx++matrix:+  include:+    - compiler: "ghc-7.4.2"+    # env: TEST=--disable-tests BENCH=--disable-benchmarks+      addons: {apt: {packages: [ghc-ppa-tools,cabal-install-head,ghc-7.4.2], sources: [hvr-ghc]}}+    - compiler: "ghc-7.6.3"+    # env: TEST=--disable-tests BENCH=--disable-benchmarks+      addons: {apt: {packages: [ghc-ppa-tools,cabal-install-head,ghc-7.6.3], sources: [hvr-ghc]}}+    - compiler: "ghc-7.8.4"+    # env: TEST=--disable-tests BENCH=--disable-benchmarks+      addons: {apt: {packages: [ghc-ppa-tools,cabal-install-head,ghc-7.8.4], sources: [hvr-ghc]}}+    - compiler: "ghc-7.10.3"+    # env: TEST=--disable-tests BENCH=--disable-benchmarks+      addons: {apt: {packages: [ghc-ppa-tools,cabal-install-head,ghc-7.10.3], sources: [hvr-ghc]}}+    - compiler: "ghc-8.0.2"+    # env: TEST=--disable-tests BENCH=--disable-benchmarks+      addons: {apt: {packages: [ghc-ppa-tools,cabal-install-head,ghc-8.0.2], sources: [hvr-ghc]}}+    - compiler: "ghc-8.2.1"+    # env: TEST=--disable-tests BENCH=--disable-benchmarks+      addons: {apt: {packages: [ghc-ppa-tools,cabal-install-head,ghc-8.2.1], sources: [hvr-ghc]}}++before_install:+ - HC=${CC}+ - HCPKG=${HC/ghc/ghc-pkg}+ - unset CC+ - PATH=/opt/ghc/bin:/opt/ghc-ppa-tools/bin:$PATH+ - PKGNAME='dollaridoos'++install:+ - cabal --version+ - echo "$(${HC} --version) [$(${HC} --print-project-git-commit-id 2> /dev/null || echo '?')]"+ - BENCH=${BENCH---enable-benchmarks}+ - TEST=${TEST---enable-tests}+ - HADDOCK=${HADDOCK-true}+ - INSTALLED=${INSTALLED-true}+ - travis_retry cabal update -v+ - sed -i.bak 's/^jobs:/-- jobs:/' ${HOME}/.cabal/config+ - rm -fv cabal.project.local+ - "echo 'packages: .' > cabal.project"+ - rm -f cabal.project.freeze+ - cabal new-build -w ${HC} ${TEST} ${BENCH} --dep -j2 all+ - cabal new-build -w ${HC} --disable-tests --disable-benchmarks --dep -j2 all++# Here starts the actual work to be performed for the package under test;+# any command which exits with a non-zero exit code causes the build to fail.+script:+ - if [ -f configure.ac ]; then autoreconf -i; fi+ - rm -rf .ghc.environment.* dist/+ - cabal sdist # test that a source-distribution can be generated+ - cd dist/+ - SRCTAR=(${PKGNAME}-*.tar.gz)+ - SRC_BASENAME="${SRCTAR/%.tar.gz}"+ - tar -xvf "./$SRC_BASENAME.tar.gz"+ - cd "$SRC_BASENAME/"+## from here on, CWD is inside the extracted source-tarball+ - rm -fv cabal.project.local+ - "echo 'packages: .' > cabal.project"+ # this builds all libraries and executables (without tests/benchmarks)+ - rm -f cabal.project.freeze+ - cabal new-build -w ${HC} --disable-tests --disable-benchmarks all+ # this builds all libraries and executables (including tests/benchmarks)+ # - rm -rf ./dist-newstyle++ # Build with installed constraints for packages in global-db+ - if $INSTALLED; then+     echo cabal new-build -w ${HC} --disable-tests --disable-benchmarks $(${HCPKG} list --global --simple-output --names-only | sed 's/\([a-zA-Z0-9-]\{1,\}\) */--constraint="\1 installed" /g') all | sh;+   else echo "Not building with installed constraints"; fi++ # build & run tests, build benchmarks+ - cabal new-build -w ${HC} ${TEST} ${BENCH} all++ # haddock+ - rm -rf ./dist-newstyle+ - if $HADDOCK; then cabal new-haddock -w ${HC} --disable-tests --disable-benchmarks all; else echo "Skipping haddock generation";fi++# REGENDATA ["dollaridoos.cabal"]+# EOF
+ CHANGELOG.md view
@@ -0,0 +1,5 @@+0.1.00+----++* Initial release+
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2015, George Wilson++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 George Wilson 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.md view
@@ -0,0 +1,15 @@+Dollaridoos+-----++![Data61](http://i.imgur.com/uZnp9ke.png)++[![Build Status](https://travis-ci.org/qfpl/dollaridoos.svg?branch=master)](https://travis-ci.org/qfpl/dollaridoos)++The money library provides a typesafe wrapper around numeric types+that allows only those operations which are sensible in the context of+monetary sums.+For instance, adding two monetary values together makes sense, but+multiplying money by money doesn't make any sense.+Functions are also provided to multiply money by constants, among+other things.+
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ dollaridoos.cabal view
@@ -0,0 +1,35 @@+name:                dollaridoos+version:             0.1.0.0+license:             BSD3+license-file:        LICENSE+author:              George Wilson+maintainer:          george@wils.online+copyright:           Copyright (c) 2017, Commonwealth Scientific and Industrial Research Organisation (CSIRO) ABN 41 687 119 230.+synopsis:            A newtype for monetary values+description:         A newtype for money with appropriate operations defined and no nonsensical instances+homepage:            https://github.com/qfpl/dollaridoos+bug-reports:         https://github.com/qfpl/dollaridoos/issues+cabal-version:       >=1.10+category:            Finance+build-type:          Simple+tested-with:         GHC == 7.4.2, GHC == 7.6.3, GHC == 7.8.4, GHC == 7.10.3, GHC == 8.0.2, GHC == 8.2.1+extra-source-files:+                     .gitignore+                     .travis.yml+                     CHANGELOG.md+                     README.md++source-repository   head+  type: git+  location: git://github.com/qfpl/dollaridoos.git++library+  exposed-modules:     Data.Money+  other-extensions:    RankNTypes+  ghc-options:         -Wall+  build-depends:+    base >= 4.5 && < 5+    , profunctors >= 4 && < 6+    , semigroups >= 0.8.4 && < 1+  hs-source-dirs:      src+  default-language:    Haskell2010
+ src/Data/Money.hs view
@@ -0,0 +1,108 @@+{-# LANGUAGE RankNTypes #-}++-- | A data type for monetary values, with associated operations and+--   only sensible instances.+module Data.Money+  (+    Money(Money)+  -- * Optics+  , money+  -- * Operators+  , ($+$)+  , ($-$)+  , (*$)+  , ($*)+  , ($/)+  , ($/$)+  , ($^)+  , ($^^)+  , ($**)+  ) where++import Data.Functor (Functor (fmap))+import Data.Foldable (Foldable (foldMap))+import Data.Monoid (Monoid, mempty, mappend)+import Data.Profunctor (Profunctor, dimap)+import Data.Semigroup (Semigroup, (<>))+import Data.Traversable (Traversable (traverse))++-- | A newtype for monetary values represented as type @num@.+--+--   The 'Semigroup' instance allows amounts of money to be added together.+--+--   Any 'Num' instances present are hidden, as operations like multiplying+--   money by money don't make any sense.+newtype Money num =+  Money num+  deriving (Eq, Ord)++instance Show num => Show (Money num) where+  show (Money m) = '$': show m++instance Num a => Semigroup (Money a) where+  Money m <> Money n = Money (m + n)++instance Num a => Monoid (Money a) where+  mappend = (<>)+  mempty = Money 0++instance Functor Money where+  fmap f (Money n) = Money (f n)++instance Foldable Money where+  foldMap f (Money n) = f n++instance Traversable Money where+  traverse f (Money n) = fmap Money (f n)++type Iso s t a b = forall p f. (Profunctor p, Functor f) => p a (f b) -> p s (f t)++-- | The raw numeric value inside monetary value+money :: Iso (Money a) (Money b) a b+money = dimap (\(Money a) -> a) (fmap Money)++-- | Add money to money. A synonym for @<>@.+infixl 6 $+$+($+$) :: Num a => Money a -> Money a -> Money a+($+$) = (<>)++-- | Subtract money from money+infixl 6 $-$+($-$) :: Num a => Money a -> Money a -> Money a+($-$) (Money m) (Money n) = Money (m - n)++-- | Multiply a scalar by money+infixr 7 *$+(*$) :: Num a => a -> Money a -> Money a+(*$) x (Money m) = Money (x * m)++-- | Multiply money by a scalar+infixl 7 $*+($*) :: Num a => Money a -> a -> Money a+($*) = flip (*$)++-- | Divide money by a scalar+infixl 7 $/+($/) :: Fractional a => Money a -> a -> Money a+($/) (Money m) x = Money (m/x)++-- | Divide money by money+infixl 7 $/$+($/$) :: Fractional a => Money a -> Money a -> a+($/$) (Money n) (Money m) = n / m++-- | Raise money to a non-negative integral power+infixr 8 $^+($^) :: (Num a, Integral b) => Money a -> b -> Money a+($^) (Money m) x = Money (m ^ x)++-- | Raise money to an integral power+infixr 8 $^^+($^^) :: (Fractional a, Integral b) => Money a -> b -> Money a+($^^) (Money m) x = Money (m ^^ x)++-- | Raise money to a floating-point power+infixr 8 $**+($**) :: Floating a => Money a -> a -> Money a+($**) (Money m) x = Money (m ** x)+