From 763e4bb2ffbf3c9319a56f19e86a06f0615ee4a7 Mon Sep 17 00:00:00 2001 From: Tony Day Date: Tue, 21 Aug 2018 13:48:30 +1000 Subject: [PATCH 01/10] 8.6.0-beta1 --- .travis.yml | 8 +- hunit-numhask/stack.yaml | 8 -- numhask-array/numhask-array.cabal | 9 +- numhask-array/stack.yaml | 10 -- numhask-bench/numhask-bench.cabal | 5 +- numhask-bench/stack.yaml | 17 --- numhask-hedgehog/numhask-hedgehog.cabal | 3 - numhask-hedgehog/stack.yaml | 8 -- numhask-prelude/numhask-prelude.cabal | 5 +- numhask-prelude/stack.yaml | 8 -- numhask/numhask.cabal | 5 +- .../src/NumHask/Algebra/Abstract/Additive.hs | 3 + numhask/stack.yaml | 3 - stack.yaml | 104 +++++++++++++++++- 14 files changed, 112 insertions(+), 84 deletions(-) delete mode 100644 hunit-numhask/stack.yaml delete mode 100644 numhask-array/stack.yaml delete mode 100644 numhask-bench/stack.yaml delete mode 100644 numhask-hedgehog/stack.yaml delete mode 100644 numhask-prelude/stack.yaml delete mode 100644 numhask/stack.yaml diff --git a/.travis.yml b/.travis.yml index 8d93d50..ce78974 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,10 +21,10 @@ ghc: - 8.4.3 env: - - PACKAGEDIR="numhask" - - PACKAGEDIR="numhask-prelude" - - PACKAGEDIR="numhask-array" - - PACKAGEDIR="numhask-hedgehog" + #- PACKAGEDIR="numhask" + #- PACKAGEDIR="numhask-prelude" + #- PACKAGEDIR="numhask-array" + #- PACKAGEDIR="numhask-hedgehog" matrix: allow_failures: diff --git a/hunit-numhask/stack.yaml b/hunit-numhask/stack.yaml deleted file mode 100644 index 3c53d5f..0000000 --- a/hunit-numhask/stack.yaml +++ /dev/null @@ -1,8 +0,0 @@ -resolver: nightly-2018-07-08 - -packages: -- . -- ../numhask - -extra-deps: [] - diff --git a/numhask-array/numhask-array.cabal b/numhask-array/numhask-array.cabal index 115a9e6..5f98924 100644 --- a/numhask-array/numhask-array.cabal +++ b/numhask-array/numhask-array.cabal @@ -27,9 +27,6 @@ build-type: cabal-version: >= 1.18 -extra-source-files: - stack.yaml - source-repository head type: git @@ -51,14 +48,14 @@ library -Wincomplete-uni-patterns -Wredundant-constraints build-depends: - base >=4.11 && <4.12 + base >=4.11 && <4.13 , adjunctions >=4.0 && <5 , deepseq >=1.4.2.0 && <2 , dimensions >=0.3.2.0 && <0.4 , distributive >=0.4 && <0.6 - , numhask-prelude >=0.3 && <0.4 + , numhask-prelude , numhask-hedgehog - , protolude >=0.1 && <0.3 + , protolude , singletons >=2.0 && <2.5 , vector >=0.10 && <0.13 exposed-modules: diff --git a/numhask-array/stack.yaml b/numhask-array/stack.yaml deleted file mode 100644 index c8185e6..0000000 --- a/numhask-array/stack.yaml +++ /dev/null @@ -1,10 +0,0 @@ -resolver: nightly-2018-07-08 - -packages: - - . - - ../numhask - - ../numhask-prelude - - ../numhask-hedgehog - -extra-deps: - - dimensions-0.3.2.0 # not on stack diff --git a/numhask-bench/numhask-bench.cabal b/numhask-bench/numhask-bench.cabal index 1a3b89e..2490e94 100644 --- a/numhask-bench/numhask-bench.cabal +++ b/numhask-bench/numhask-bench.cabal @@ -25,9 +25,6 @@ build-type: cabal-version: >= 1.18 -extra-source-files: - stack.yaml - source-repository head type: git @@ -52,7 +49,7 @@ executable numhask-bench -Wincomplete-uni-patterns -Wredundant-constraints build-depends: - base >=4.7 && <5 + base >=4.7 && <4.13 , hmatrix , matrix , numhask diff --git a/numhask-bench/stack.yaml b/numhask-bench/stack.yaml deleted file mode 100644 index 00f091a..0000000 --- a/numhask-bench/stack.yaml +++ /dev/null @@ -1,17 +0,0 @@ -resolver: nightly-2018-07-08 - -packages: - - . - - ../numhask - - ../numhask-prelude - - ../numhask-array - - ../numhask-hedgehog - -extra-deps: - - dimensions-0.3.2.0 - - tdigest-0.2 - - perf-0.4.1.0 - - perf-analysis-0.0.1.1 - -allow-newer: true - diff --git a/numhask-hedgehog/numhask-hedgehog.cabal b/numhask-hedgehog/numhask-hedgehog.cabal index 344e28b..ca6e86d 100644 --- a/numhask-hedgehog/numhask-hedgehog.cabal +++ b/numhask-hedgehog/numhask-hedgehog.cabal @@ -25,9 +25,6 @@ build-type: cabal-version: >= 1.18 -extra-source-files: - stack.yaml - source-repository head type: git diff --git a/numhask-hedgehog/stack.yaml b/numhask-hedgehog/stack.yaml deleted file mode 100644 index 4eab694..0000000 --- a/numhask-hedgehog/stack.yaml +++ /dev/null @@ -1,8 +0,0 @@ -resolver: nightly-2018-07-08 - -packages: - - . - - ../numhask - - ../numhask-prelude - -extra-deps: [] diff --git a/numhask-prelude/numhask-prelude.cabal b/numhask-prelude/numhask-prelude.cabal index e084e13..18ee36b 100644 --- a/numhask-prelude/numhask-prelude.cabal +++ b/numhask-prelude/numhask-prelude.cabal @@ -25,9 +25,6 @@ build-type: cabal-version: >= 1.18 -extra-source-files: - stack.yaml - source-repository head type: git location: https://github.com/tonyday567/numhask @@ -47,7 +44,7 @@ library -Wincomplete-uni-patterns -Wredundant-constraints build-depends: - base >=4.7 && <4.12 + base >=4.7 && <4.13 , numhask >=0.3 && <0.4 , protolude >=0.1 && <0.3 exposed-modules: diff --git a/numhask-prelude/stack.yaml b/numhask-prelude/stack.yaml deleted file mode 100644 index 4105f6e..0000000 --- a/numhask-prelude/stack.yaml +++ /dev/null @@ -1,8 +0,0 @@ -resolver: nightly-2018-07-08 - -packages: - - . - - ../numhask - -extra-deps: - # - numhask-0.2.3.0 diff --git a/numhask/numhask.cabal b/numhask/numhask.cabal index fc0c200..1928b32 100644 --- a/numhask/numhask.cabal +++ b/numhask/numhask.cabal @@ -25,9 +25,6 @@ build-type: cabal-version: >= 1.18 -extra-source-files: - stack.yaml - extra-doc-files: other/*.svg @@ -49,7 +46,7 @@ library -Wincomplete-uni-patterns -Wredundant-constraints build-depends: - base >=4.7 && <4.12 + base >=4.7 && <4.13 exposed-modules: NumHask.Algebra.Abstract NumHask.Algebra.Abstract.Action diff --git a/numhask/src/NumHask/Algebra/Abstract/Additive.hs b/numhask/src/NumHask/Algebra/Abstract/Additive.hs index 15ae6a3..b04ae4e 100644 --- a/numhask/src/NumHask/Algebra/Abstract/Additive.hs +++ b/numhask/src/NumHask/Algebra/Abstract/Additive.hs @@ -8,6 +8,7 @@ {-# LANGUAGE UndecidableInstances #-} {-# LANGUAGE TypeApplications #-} {-# LANGUAGE ScopedTypeVariables #-} +{-# LANGUAGE RoleAnnotations #-} {-# OPTIONS_GHC -Wall #-} -- | Additive @@ -30,6 +31,8 @@ newtype Sum a = Sum a deriving (P.Eq, P.Ord, P.Read, P.Show, P.Bounded, P.Generic, P.Generic1, P.Functor) +type role Sum representational + class (Associative (Sum a), Commutative (Sum a), Unital (Sum a)) => Additive a where sum :: (P.Foldable f) => f a -> a diff --git a/numhask/stack.yaml b/numhask/stack.yaml deleted file mode 100644 index 301bab7..0000000 --- a/numhask/stack.yaml +++ /dev/null @@ -1,3 +0,0 @@ -resolver: nightly-2018-07-08 - -extra-deps: [] diff --git a/stack.yaml b/stack.yaml index 64725fe..d8fb0a0 100644 --- a/stack.yaml +++ b/stack.yaml @@ -1,13 +1,107 @@ resolver: nightly-2018-07-08 packages: + # - hunit-numhask - numhask - numhask-prelude - - numhask-array + # - numhask-array - numhask-hedgehog - - numhask-bench + # - numhask-bench extra-deps: - - dimensions-0.3.2.0 - - perf-0.4.1.0 - - perf-analysis-0.0.1.1 + # - dimensions-0.3.2.0 + # - perf-0.4.1.0 + # - perf-analysis-0.0.1.1 + + # base-4.12 libraries + - async-2.2.1 + - hashable-1.2.7.0 + - mtl-compat-0.2.1.3 + - transformers-compat-0.6.2 + + # tests + - doctest-0.16.0 + - base-compat-0.10.4 + - code-page-0.1.3 + - ghc-paths-0.1.0.9 + - syb-0.7 + - hedgehog-0.6 + - ansi-terminal-0.8.0.4 + - concurrent-output-1.10.6 + - exceptions-0.10.0 + - lifted-async-0.10.0.2 + - mmorph-1.1.2 + - monad-control-1.0.2.3 + - pretty-show-1.7 + - primitive-0.6.4.0 + - random-1.1 + - resourcet-1.2.1 + - semigroups-0.18.5 + - th-lift-0.7.10 + - transformers-base-0.4.5.2 + - wl-pprint-annotated-0.1.0.1 + - base-orphans-0.8 + - colour-2.3.4 + - constraints-0.10.1 + - haskell-lexer-1.0.1 + - lifted-base-0.2.3.12 + - terminal-size-0.3.2.1 + - th-abstraction-0.2.8.0 + - unliftio-core-0.1.1.0 + + # pretty-show dep + - happy-1.19.9@sha256:e794416736049cefc904bba746b5315f8cfb6fd6457a90616eb1f3c8dd47b1ff + + # ghc-8.6 deps + - github: haskell/cabal + commit: 81a90a0a24600ce03c7eda6f3f92336c157d9ecc + subdirs: + - Cabal + - cabal-install + + - github: sdiehl/protolude + commit: 1b1f82b749b100f48c8f9f91e90177d14791e6c0 + + - github: haskell/stm + commit: 4a1deb98fc95e55d8a6762a7dfec1a7dfa8b49b2 + + +# https://gist.github.com/DanBurton/43b5f5155fdd1affd02f6e86f37da9ae +setup-info: + ghc: + windows32: + 8.6.0.20180810: + url: https://downloads.haskell.org/~ghc/8.6.1-beta1/ghc-8.6.0.20180810-i386-unknown-mingw32.tar.xz + sha256: 9be35662d510d3489ddd583e7d9d38ee6b6ba40b852f6e90e0dfd97a0d7bbfd3 + linux32-nopie: + 8.6.0.20180810: + url: https://downloads.haskell.org/~ghc/8.6.1-beta1/ghc-8.6.0.20180810-i386-deb8-linux.tar.xz + sha256: 99a1abec3b349a8e676daa39619c5cbf44795f34ce2113c00c2dbac9f53eaf6d + macosx: + 8.6.0.20180810: + url: https://downloads.haskell.org/~ghc/8.6.1-beta1/ghc-8.6.0.20180810-x86_64-darwin.tar.xz + sha256: 53fcac63a4eb04970a47f63c123076d14946208033e0811e90357831995f541a + windows64: + 8.6.0.20180810: + url: https://downloads.haskell.org/~ghc/8.6.1-beta1/ghc-8.6.0.20180810-x86_64-unknown-mingw32.tar.xz + sha256: f6492ac6a6561e78b43e905c3cee260d64246868b88bfb177de5b29d3029783c + linux64-nopie: + 8.6.0.20180810: + url: https://downloads.haskell.org/~ghc/8.6.1-beta1/ghc-8.6.0.20180810-x86_64-deb8-linux.tar.xz + sha256: 69e2e5c579e71c5fed1cf9be9760af4bce5f99865211c8eb6073722b8baffbd9 + linux64-tinfo: + 8.6.0.20180810: + url: https://downloads.haskell.org/~ghc/8.6.1-beta1/ghc-8.6.0.20180810-x86_64-fedora27-linux.tar.xz + sha256: b59ef0d92bd2e9baaa3cff7a3c1a6cfad0cdde749afae33e9db78e772ed9f8a0 + linux64-tinfo-nopie: + 8.6.0.20180810: + url: https://downloads.haskell.org/~ghc/8.6.1-beta1/ghc-8.6.0.20180810-x86_64-fedora27-linux.tar.xz + sha256: b59ef0d92bd2e9baaa3cff7a3c1a6cfad0cdde749afae33e9db78e772ed9f8a0 + +resolver: ghc-8.6.0.20180810 +compiler: ghc-8.6.0.20180810 +compiler-check: match-exact + +system-ghc: false + +allow-newer: true From c6146881a69fdf554bd42c98d0ed79978358b005 Mon Sep 17 00:00:00 2001 From: Tony Day Date: Tue, 21 Aug 2018 19:31:43 +1000 Subject: [PATCH 02/10] simplify travis --- .travis.yml | 37 ++++++++++--------------------------- 1 file changed, 10 insertions(+), 27 deletions(-) diff --git a/.travis.yml b/.travis.yml index ce78974..a1c28eb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,9 +5,9 @@ # https://github.com/commercialhaskell/stack/blob/master/.travis.yml # https://github.com/ekmett/intervals/blob/master/.travis.yml -sudo: true +sudo: false -language: haskell +language: generic # Caching so the next build will be fast too. cache: @@ -15,22 +15,6 @@ cache: - $HOME/.stack - $HOME/build/tonyday567/numhask/.stack-work -ghc: - - head - # - 8.6.1 - - 8.4.3 - -env: - #- PACKAGEDIR="numhask" - #- PACKAGEDIR="numhask-prelude" - #- PACKAGEDIR="numhask-array" - #- PACKAGEDIR="numhask-hedgehog" - -matrix: - allow_failures: - - ghc: head - - ghc: ghc-8.6.1 - # Ensure necessary system libraries are present addons: apt: @@ -42,16 +26,15 @@ addons: - cabal-install-head # required by GHC head before_install: - - cd ${PACKAGEDIR} +# Download and unpack the stack executable +- mkdir -p ~/.local/bin +- export PATH=$HOME/.local/bin:$PATH +- travis_retry curl -L https://www.stackage.org/stack/linux-x86_64 | tar xz --wildcards --strip-components=1 -C ~/.local/bin '*/stack' install: - # Download and unpack the stack executable - - mkdir -p ~/.local/bin - - export PATH=$HOME/.local/bin:$PATH - - travis_retry curl -L https://www.stackage.org/stack/linux-x86_64 | tar xz --wildcards --strip-components=1 -C ~/.local/bin '*/stack' - # Build dependencies - - stack --no-terminal --install-ghc test --only-dependencies +# Build dependencies +- stack --no-terminal --install-ghc test --only-dependencies script: - # Build the package, its tests, and its docs and run the tests - - stack --no-terminal test --haddock --no-haddock-deps +# Build the package, its tests, and its docs and run the tests +- stack --no-terminal test --haddock --no-haddock-deps From a8cf9e6c0ea47387ba17b61305c6b87be88eb7e9 Mon Sep 17 00:00:00 2001 From: Tony Day Date: Thu, 23 Aug 2018 11:06:50 +1000 Subject: [PATCH 03/10] Trying the boiler-plate old travis config. --- .travis.yml | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/.travis.yml b/.travis.yml index a1c28eb..ad53513 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,29 +1,29 @@ -# https://serokell.io/posts/2018-01-24-using-travis-CI-for-Haskell-projects.html -# also see: -# https://docs.travis-ci.com/user/customizing-the-build/#Build-Matrix +# This is the simple Travis configuration, which is intended for use +# on applications which do not require cross-platform and +# multiple-GHC-version support. For more information and other +# options, see: +# # https://docs.haskellstack.org/en/stable/travis_ci/ -# https://github.com/commercialhaskell/stack/blob/master/.travis.yml -# https://github.com/ekmett/intervals/blob/master/.travis.yml +# +# Copy these contents into the root directory of your Github project in a file +# named .travis.yml +# Use new container infrastructure to enable caching sudo: false +# Do not choose a language; we provide our own build tools. language: generic # Caching so the next build will be fast too. cache: directories: - $HOME/.stack - - $HOME/build/tonyday567/numhask/.stack-work # Ensure necessary system libraries are present addons: apt: - sources: - - sourceline: 'ppa:hvr/ghc' # PPA of Haskell packages packages: - - libgmp-dev # required by cabal - - cabal-install-2.2 # required by GHC 8.* - - cabal-install-head # required by GHC head + - libgmp-dev before_install: # Download and unpack the stack executable From 39b2a2251fbbfa573baaaf4f76ddf0284c69eb72 Mon Sep 17 00:00:00 2001 From: Tony Day Date: Thu, 23 Aug 2018 11:13:21 +1000 Subject: [PATCH 04/10] copied linux64-nopie --- stack.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/stack.yaml b/stack.yaml index d8fb0a0..b991f24 100644 --- a/stack.yaml +++ b/stack.yaml @@ -89,6 +89,10 @@ setup-info: 8.6.0.20180810: url: https://downloads.haskell.org/~ghc/8.6.1-beta1/ghc-8.6.0.20180810-x86_64-deb8-linux.tar.xz sha256: 69e2e5c579e71c5fed1cf9be9760af4bce5f99865211c8eb6073722b8baffbd9 + linux64: + 8.6.0.20180810: + url: https://downloads.haskell.org/~ghc/8.6.1-beta1/ghc-8.6.0.20180810-x86_64-deb8-linux.tar.xz + sha256: 69e2e5c579e71c5fed1cf9be9760af4bce5f99865211c8eb6073722b8baffbd9 linux64-tinfo: 8.6.0.20180810: url: https://downloads.haskell.org/~ghc/8.6.1-beta1/ghc-8.6.0.20180810-x86_64-fedora27-linux.tar.xz From e37243ecbb60da560d83c545e7268c64c8f5cb92 Mon Sep 17 00:00:00 2001 From: Tony Day Date: Tue, 11 Sep 2018 11:26:17 +1000 Subject: [PATCH 05/10] stack.yaml removals --- hunit-numhask/.gitignore | 4 --- hunit-numhask/.travis.yml | 34 ------------------------- hunit-numhask/README.md | 5 ---- hunit-numhask/hunit-numhask.cabal | 9 +++---- hunit-numhask/stack.yaml | 8 ------ numhask-array/numhask-array.cabal | 9 +++---- numhask-array/stack.yaml | 11 -------- numhask-bench/numhask-bench.cabal | 9 +++---- numhask-bench/stack.yaml | 17 ------------- numhask-hedgehog/numhask-hedgehog.cabal | 8 ++---- numhask-hedgehog/stack.yaml | 9 ------- numhask-prelude/numhask-prelude.cabal | 13 +++++----- numhask-prelude/stack.yaml | 8 ------ numhask-space/numhask-space.cabal | 13 +++++----- numhask-space/stack.yaml | 7 ----- numhask/numhask.cabal | 12 ++++----- numhask/stack.yaml | 3 --- stack.yaml | 1 + 18 files changed, 30 insertions(+), 150 deletions(-) delete mode 100644 hunit-numhask/.gitignore delete mode 100644 hunit-numhask/.travis.yml delete mode 100644 hunit-numhask/README.md delete mode 100644 hunit-numhask/stack.yaml delete mode 100644 numhask-array/stack.yaml delete mode 100644 numhask-bench/stack.yaml delete mode 100644 numhask-hedgehog/stack.yaml delete mode 100644 numhask-prelude/stack.yaml delete mode 100644 numhask-space/stack.yaml delete mode 100644 numhask/stack.yaml diff --git a/hunit-numhask/.gitignore b/hunit-numhask/.gitignore deleted file mode 100644 index 966e62c..0000000 --- a/hunit-numhask/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -/dist/ -/.cabal-sandbox/ -/cabal.sandbox.config -/.stack-work/ diff --git a/hunit-numhask/.travis.yml b/hunit-numhask/.travis.yml deleted file mode 100644 index 082a28b..0000000 --- a/hunit-numhask/.travis.yml +++ /dev/null @@ -1,34 +0,0 @@ -# Use new container infrastructure to enable caching -sudo: false - -# Choose a lightweight base image; we provide our own build tools. -language: c - -# GHC depends on GMP. You can add other dependencies here as well. -addons: - apt: - packages: - - libgmp-dev - -# The different configurations we want to test. You could also do things like -# change flags or use --stack-yaml to point to a different file. -env: -- ARGS="" -- ARGS="--resolver lts" -- ARGS="--resolver nightly-2018-04-04" - -before_install: -# Download and unpack the stack executable -- mkdir -p ~/.local/bin -- export PATH=$HOME/.local/bin:$PATH -- travis_retry curl -L https://www.stackage.org/stack/linux-x86_64 | tar xz --wildcards --strip-components=1 -C ~/.local/bin '*/stack' - -# This line does all of the work: installs GHC if necessary, build the library, -# executables, and test suites, and runs the test suites. --no-terminal works -# around some quirks in Travis's terminal implementation. -script: stack $ARGS --no-terminal --install-ghc test --haddock - -# Caching so the next build will be fast too. -cache: - directories: - - $HOME/.stack \ No newline at end of file diff --git a/hunit-numhask/README.md b/hunit-numhask/README.md deleted file mode 100644 index 0b804a0..0000000 --- a/hunit-numhask/README.md +++ /dev/null @@ -1,5 +0,0 @@ -# hunit-numhask - -[![Build Status](https://travis-ci.org/githubuser/hunit-numhask.png)](https://travis-ci.org/githubuser/hunit-numhask) - -TODO Description. diff --git a/hunit-numhask/hunit-numhask.cabal b/hunit-numhask/hunit-numhask.cabal index 8f5564c..2d2150e 100644 --- a/hunit-numhask/hunit-numhask.cabal +++ b/hunit-numhask/hunit-numhask.cabal @@ -16,13 +16,10 @@ category: Test build-type: Simple -extra-source-files: - README.md cabal-version: >=1.18 tested-with: GHC == 8.4.1 - library default-language: Haskell2010 ghc-options: @@ -36,7 +33,6 @@ library , exceptions , HUnit , numhask - test-suite spec default-language: Haskell2010 ghc-options: @@ -54,9 +50,10 @@ test-suite spec , hunit-numhask , hspec , QuickCheck - source-repository head type: git location: - https://github.com/githubuser/hunit-numhask + https://github.com/tonyday567/numhask + subdir: + hunit-numhask diff --git a/hunit-numhask/stack.yaml b/hunit-numhask/stack.yaml deleted file mode 100644 index 3c53d5f..0000000 --- a/hunit-numhask/stack.yaml +++ /dev/null @@ -1,8 +0,0 @@ -resolver: nightly-2018-07-08 - -packages: -- . -- ../numhask - -extra-deps: [] - diff --git a/numhask-array/numhask-array.cabal b/numhask-array/numhask-array.cabal index 115a9e6..1a7a303 100644 --- a/numhask-array/numhask-array.cabal +++ b/numhask-array/numhask-array.cabal @@ -26,16 +26,13 @@ build-type: Simple cabal-version: >= 1.18 - -extra-source-files: - stack.yaml - source-repository head type: git location: - https://github.com/tonyday567/numhask-array - + https://github.com/tonyday567/numhask + subdir: + numhask-array library hs-source-dirs: src diff --git a/numhask-array/stack.yaml b/numhask-array/stack.yaml deleted file mode 100644 index 438d146..0000000 --- a/numhask-array/stack.yaml +++ /dev/null @@ -1,11 +0,0 @@ -resolver: nightly-2018-07-08 - -packages: - - . - - ../numhask - - ../numhask-prelude - - ../numhask-hedgehog - - ../numhask-space - -extra-deps: - - dimensions-0.3.2.0 # not on stack diff --git a/numhask-bench/numhask-bench.cabal b/numhask-bench/numhask-bench.cabal index 1a3b89e..7a415eb 100644 --- a/numhask-bench/numhask-bench.cabal +++ b/numhask-bench/numhask-bench.cabal @@ -24,16 +24,13 @@ build-type: Simple cabal-version: >= 1.18 - -extra-source-files: - stack.yaml - source-repository head type: git location: - https://github.com/tonyday567/numhask-bench - + https://github.com/tonyday567/numhask + subdir: + numhask-array executable numhask-bench main-is: bench.hs diff --git a/numhask-bench/stack.yaml b/numhask-bench/stack.yaml deleted file mode 100644 index 00f091a..0000000 --- a/numhask-bench/stack.yaml +++ /dev/null @@ -1,17 +0,0 @@ -resolver: nightly-2018-07-08 - -packages: - - . - - ../numhask - - ../numhask-prelude - - ../numhask-array - - ../numhask-hedgehog - -extra-deps: - - dimensions-0.3.2.0 - - tdigest-0.2 - - perf-0.4.1.0 - - perf-analysis-0.0.1.1 - -allow-newer: true - diff --git a/numhask-hedgehog/numhask-hedgehog.cabal b/numhask-hedgehog/numhask-hedgehog.cabal index e0ea0ac..379ee42 100644 --- a/numhask-hedgehog/numhask-hedgehog.cabal +++ b/numhask-hedgehog/numhask-hedgehog.cabal @@ -24,16 +24,13 @@ build-type: Simple cabal-version: >= 1.18 - -extra-source-files: - stack.yaml - source-repository head type: git location: https://github.com/tonyday567/numhask - + subdir: + numhask-hedgehog library hs-source-dirs: src @@ -61,7 +58,6 @@ library NumHask.Hedgehog.Prop.Space NumHask.Hedgehog.Props default-language: Haskell2010 - test-suite test type: exitcode-stdio-1.0 diff --git a/numhask-hedgehog/stack.yaml b/numhask-hedgehog/stack.yaml deleted file mode 100644 index d5ddc3e..0000000 --- a/numhask-hedgehog/stack.yaml +++ /dev/null @@ -1,9 +0,0 @@ -resolver: nightly-2018-07-08 - -packages: - - . - - ../numhask - - ../numhask-prelude - - ../numhask-space - -extra-deps: [] diff --git a/numhask-prelude/numhask-prelude.cabal b/numhask-prelude/numhask-prelude.cabal index 763020f..4cffb7c 100644 --- a/numhask-prelude/numhask-prelude.cabal +++ b/numhask-prelude/numhask-prelude.cabal @@ -24,14 +24,13 @@ build-type: Simple cabal-version: >= 1.18 - -extra-source-files: - stack.yaml - source-repository head - type: git - location: https://github.com/tonyday567/numhask - + type: + git + location: + https://github.com/tonyday567/numhask + subdir: + numhask-prelude library hs-source-dirs: src diff --git a/numhask-prelude/stack.yaml b/numhask-prelude/stack.yaml deleted file mode 100644 index 26c7bee..0000000 --- a/numhask-prelude/stack.yaml +++ /dev/null @@ -1,8 +0,0 @@ -resolver: nightly-2018-07-08 - -packages: - - . - - ../numhask - - ../numhask-space - -extra-deps: [] diff --git a/numhask-space/numhask-space.cabal b/numhask-space/numhask-space.cabal index 722c638..de052fe 100644 --- a/numhask-space/numhask-space.cabal +++ b/numhask-space/numhask-space.cabal @@ -24,14 +24,13 @@ build-type: Simple cabal-version: >= 1.18 - -extra-source-files: - stack.yaml - source-repository head - type: git - location: https://github.com/tonyday567/numhask - + type: + git + location: + https://github.com/tonyday567/numhask + subdir: + numhask-space library hs-source-dirs: src diff --git a/numhask-space/stack.yaml b/numhask-space/stack.yaml deleted file mode 100644 index d8cf190..0000000 --- a/numhask-space/stack.yaml +++ /dev/null @@ -1,7 +0,0 @@ -resolver: nightly-2018-07-08 - -packages: - - . - - ../numhask - -extra-deps: [] diff --git a/numhask/numhask.cabal b/numhask/numhask.cabal index 0cc3bb2..b26eb14 100644 --- a/numhask/numhask.cabal +++ b/numhask/numhask.cabal @@ -25,16 +25,16 @@ build-type: cabal-version: >= 1.18 -extra-source-files: - stack.yaml - extra-doc-files: other/*.svg source-repository head - type: git - location: https://github.com/tonyday567/numhask - + type: + git + location: + https://github.com/tonyday567/numhask + subdir: + numhask library hs-source-dirs: src diff --git a/numhask/stack.yaml b/numhask/stack.yaml deleted file mode 100644 index 301bab7..0000000 --- a/numhask/stack.yaml +++ /dev/null @@ -1,3 +0,0 @@ -resolver: nightly-2018-07-08 - -extra-deps: [] diff --git a/stack.yaml b/stack.yaml index 121fe37..7654d00 100644 --- a/stack.yaml +++ b/stack.yaml @@ -1,6 +1,7 @@ resolver: nightly-2018-07-08 packages: + - hunit-numhask - numhask - numhask-prelude - numhask-array From 97d0611dafd302819565710558c755abd3492d60 Mon Sep 17 00:00:00 2001 From: Tony Day Date: Tue, 11 Sep 2018 17:29:03 +1000 Subject: [PATCH 06/10] explicit ghc-8.6.1 version --- .travis.yml | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index ad53513..5dbdae4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,6 +25,13 @@ addons: packages: - libgmp-dev +matrix: + include: + - env: YAML=stack-ghc86.yaml + - env: YAML=stack.yaml + allow_failures: + - env: YAML=stack-ghc86.yaml + before_install: # Download and unpack the stack executable - mkdir -p ~/.local/bin @@ -33,8 +40,9 @@ before_install: install: # Build dependencies -- stack --no-terminal --install-ghc test --only-dependencies - +- STACK_YAML=$YAML stack --no-terminal --install-ghc test --only-dependencies +# - STACK_YAML=stack-ghc86.yaml stack --no-terminal --install-ghc test --only-dependencies script: # Build the package, its tests, and its docs and run the tests -- stack --no-terminal test --haddock --no-haddock-deps +- STACK_YAML=$YAML stack --no-terminal test --haddock --no-haddock-deps +# - STACK_YAML=stack-ghc86.yaml stack --no-terminal test --haddock --no-haddock-deps From b93fdefbec13de5833e752eedbf05d1e0fe4bf76 Mon Sep 17 00:00:00 2001 From: Tony Day Date: Wed, 12 Sep 2018 09:16:36 +1000 Subject: [PATCH 07/10] Dropped numhask-bench due to hmatrix,, local compiling --- stack-ghc86.yaml | 17 ++++++++++++++++- stack.yaml | 3 ++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/stack-ghc86.yaml b/stack-ghc86.yaml index 1740bee..71a117a 100644 --- a/stack-ghc86.yaml +++ b/stack-ghc86.yaml @@ -5,7 +5,7 @@ packages: - numhask-prelude # - numhask-array - numhask-hedgehog - - numhask-bench + # - numhask-bench - numhask-space extra-deps: @@ -19,6 +19,21 @@ extra-deps: - mtl-compat-0.2.1.3 - transformers-compat-0.6.2 + # kmett + - adjunctions-4.4 + - distributive-0.6 + - semigroupoids-5.3.1 + - bifunctors-5.5.3@sha256:8f6e90c3ae7a04dba36669e4fad5b9fbc973dbfc6978b4c7d410f9875e0e9d00 + - cabal-doctest-1.0.6@sha256:8dde7a60291f029f27b44ad5c74739e66d8bbc0b602efe1edb7e24f6b62a68ae + - comonad-5.0.4@sha256:522ca45fedc212d86b3f628275974378e821e7f3caf8055a64189ae4f8c59dbf + - contravariant-1.5@sha256:83f4d20073414561f2352aeb8f48207def31cc933eb058c141968fbbefaeb0d5 + - free-5.1@sha256:71aa48c5a5dde71ed2a7f3d1d23c6d3a66580859444f55c8b38dd1bb205aa298 + - profunctors-5.3@sha256:ce641b72fd014b1f7b42a438f8c0360cb93fd277c7b843b7ef94a7c083c31ded + - tagged-0.8.6@sha256:b5e1de3b14ff198b548928f686e5e8783301dc231413f751c23f4ee10cd47a7c + - unordered-containers-0.2.9.0@sha256:124a5241860711a0e5c10e94d8aec8a127f0094df7a537cc1786e198d7571dfe + - void-0.7.2@sha256:e07cd23407914833bc8bf726ad27fe4696c2e38685bc00031a2ca632230124ca + - StateVar-1.1.1.1@sha256:cd3b516a49faf0627ea31885e012611e63600824976dcb276bcb2e92cdb0790f + # tests - doctest-0.16.0 - base-compat-0.10.4 diff --git a/stack.yaml b/stack.yaml index 35a7b2f..952c9dd 100644 --- a/stack.yaml +++ b/stack.yaml @@ -5,7 +5,8 @@ packages: - numhask-prelude - numhask-array - numhask-hedgehog - - numhask-bench + # issues with hmatrix + # - numhask-bench - numhask-space extra-deps: From a57f4006bfe3c639a0cbd9930cc7c40ffb29e58e Mon Sep 17 00:00:00 2001 From: Tony Day Date: Tue, 11 Sep 2018 16:56:35 +1000 Subject: [PATCH 08/10] Actor model for actions --- hunit-numhask/test/LibSpec.hs | 2 +- numhask-array/src/NumHask/Array.hs | 20 +++++----- numhask-space/src/NumHask/Data/Range.hs | 10 +++-- numhask-space/src/NumHask/Data/Rect.hs | 10 +++-- .../src/NumHask/Algebra/Abstract/Action.hs | 40 +++++++++++-------- .../src/NumHask/Algebra/Abstract/Module.hs | 3 +- numhask/src/NumHask/Analysis/Banach.hs | 21 +++++----- numhask/src/NumHask/Analysis/Metric.hs | 32 --------------- numhask/src/NumHask/Data/Complex.hs | 2 - numhask/src/NumHask/Data/Pair.hs | 32 +++++++-------- numhask/src/NumHask/Data/Positive.hs | 2 - numhask/src/NumHask/Data/Rational.hs | 2 - 12 files changed, 74 insertions(+), 102 deletions(-) diff --git a/hunit-numhask/test/LibSpec.hs b/hunit-numhask/test/LibSpec.hs index 3b44f5b..1889249 100644 --- a/hunit-numhask/test/LibSpec.hs +++ b/hunit-numhask/test/LibSpec.hs @@ -10,6 +10,6 @@ spec :: Spec spec = describe "Test.HUnit.NumHask" $ do it "Tests Float values for approximate equality" $ - (1/3 :: Float) `shouldBeAbout` 0.333333 + (1/3 :: Float) `shouldBeAbout` 0.33333334 it "Tests Double values for approximate equality" $ (1/3 :: Double) `shouldBeAbout` 0.3333333333333333 diff --git a/numhask-array/src/NumHask/Array.hs b/numhask-array/src/NumHask/Array.hs index 4ca04d4..7517195 100644 --- a/numhask-array/src/NumHask/Array.hs +++ b/numhask-array/src/NumHask/Array.hs @@ -283,7 +283,7 @@ instance -- [43, 50]] -- mmult :: forall c m n k a. - ( Hilbert (Vector c k) a + ( Hilbert (Vector c k a) , Dimensions '[ m, k] , Dimensions '[ k, n] , Dimensions '[ m, n] @@ -610,7 +610,6 @@ instance (Functor (Array c r), Foldable (Array c r), Additive (Array c r a), Nor Normed (Array c r a) a where normL1 r = foldr (+) zero $ normL1 <$> r normL2 r = sqrt $ foldr (+) zero $ (** (one + one)) <$> r - normLp p r = (** (one / p)) $ foldr (+) zero $ (** p) . normL1 <$> r instance (Eq (c a), Foldable (Array c r), Dimensions r, Container c, Epsilon a) => Epsilon (Array c r a) where @@ -622,7 +621,6 @@ instance (Foldable (Array c r), Dimensions r, Container c, ExpField a, Subtracti Metric (Array c r a) a where distanceL1 a b = normL1 (a - b) distanceL2 a b = normL2 (a - b) - distanceLp p a b = normLp p (a - b) instance (Dimensions r, Container c, Integral a) => Integral (Array c r a) where divMod a b = (d, m) @@ -636,9 +634,7 @@ instance (Dimensions r, Container c, Integral a) => Integral (Array c r a) where q = fmap fst x r = fmap snd x -instance (Foldable (Array c r), CommutativeRing a, Semiring a, Dimensions r, Container c) => - Hilbert (Array c r) a where - a <.> b = sum $ liftR2 (*) a b +type instance Actor (Array c r a) = a instance (Dimensions r, Container c, Multiplicative a) => HadamardMultiplication (Array c r) a where @@ -649,25 +645,29 @@ instance (Dimensions r, Container c, Divisive a) => (./.) = liftR2 (/) instance (Dimensions r, Container c, Additive a) => - AdditiveAction (Array c (r::[Nat])) a where + AdditiveAction (Array c (r::[Nat]) a) where (.+) r s = fmap (s +) r (+.) s = fmap (s +) instance (Dimensions r, Container c, Subtractive a) => - SubtractiveAction (Array c (r::[Nat])) a where + SubtractiveAction (Array c (r::[Nat]) a) where (.-) r s = fmap (\x -> x - s) r (-.) s = fmap (\x -> x - s) instance (Dimensions r, Container c, Multiplicative a) => - MultiplicativeAction (Array c (r :: [Nat])) a where + MultiplicativeAction (Array c (r :: [Nat]) a) where (.*) r s = fmap (* s) r (*.) s = fmap (s *) instance (Dimensions r, Container c, Divisive a) => - DivisiveAction (Array c (r::[Nat])) a where + DivisiveAction (Array c (r::[Nat]) a) where (./) r s = fmap (/ s) r (/.) s = fmap (/ s) +instance forall a c r. (Actor (Array c r a) ~ a, Foldable (Array c r), P.Distributive a, CommutativeRing a, Semiring a, Dimensions r, Container c) => + Hilbert (Array c r a) where + a <.> b = sum $ liftR2 (*) a b + instance ( Foldable (Array c r) , Dimensions r diff --git a/numhask-space/src/NumHask/Data/Range.hs b/numhask-space/src/NumHask/Data/Range.hs index 8ed5828..9597d84 100644 --- a/numhask-space/src/NumHask/Data/Range.hs +++ b/numhask-space/src/NumHask/Data/Range.hs @@ -212,16 +212,18 @@ instance (Multiplicative a, Subtractive a, Lattice a) => Signed (Range a) where instance (FromInteger a, Lattice a) => FromInteger (Range a) where fromInteger x = fromInteger x ... fromInteger x -instance (Additive a) => AdditiveAction Range a where +type instance Actor (Range a) = a + +instance (Additive a) => AdditiveAction (Range a) where (.+) r s = fmap (s+) r (+.) s = fmap (s+) -instance (Subtractive a) => SubtractiveAction Range a where +instance (Subtractive a) => SubtractiveAction (Range a) where (.-) r s = fmap (\x -> x - s) r (-.) s = fmap (\x -> x - s) -instance (Multiplicative a) => MultiplicativeAction Range a where +instance (Multiplicative a) => MultiplicativeAction (Range a) where (.*) r s = fmap (s*) r (*.) s = fmap (s*) -instance (Divisive a) => DivisiveAction Range a where +instance (Divisive a) => DivisiveAction (Range a) where (./) r s = fmap (/ s) r (/.) s = fmap (/ s) diff --git a/numhask-space/src/NumHask/Data/Rect.hs b/numhask-space/src/NumHask/Data/Rect.hs index c611447..98b1fcc 100644 --- a/numhask-space/src/NumHask/Data/Rect.hs +++ b/numhask-space/src/NumHask/Data/Rect.hs @@ -178,15 +178,17 @@ projectRect r0 r1 (Rect a b c d) = Rect a' b' c' d' (Pair a' c') = project r0 r1 (Pair a c) (Pair b' d') = project r0 r1 (Pair b d) -instance (Additive a) => AdditiveAction Rect a where +type instance Actor (Rect a) = a + +instance (Additive a) => AdditiveAction (Rect a) where (.+) r s = fmap (s+) r (+.) s = fmap (s+) -instance (Subtractive a) => SubtractiveAction Rect a where +instance (Subtractive a) => SubtractiveAction (Rect a) where (.-) r s = fmap (\x -> x - s) r (-.) s = fmap (\x -> x - s) -instance (Multiplicative a) => MultiplicativeAction Rect a where +instance (Multiplicative a) => MultiplicativeAction (Rect a) where (.*) r s = fmap (s*) r (*.) s = fmap (s*) -instance (Divisive a) => DivisiveAction Rect a where +instance (Divisive a) => DivisiveAction (Rect a) where (./) r s = fmap (/ s) r (/.) s = fmap (/ s) diff --git a/numhask/src/NumHask/Algebra/Abstract/Action.hs b/numhask/src/NumHask/Algebra/Abstract/Action.hs index e4ad030..a7f5a2d 100644 --- a/numhask/src/NumHask/Algebra/Abstract/Action.hs +++ b/numhask/src/NumHask/Algebra/Abstract/Action.hs @@ -1,9 +1,12 @@ +{-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE MultiParamTypeClasses #-} +{-# LANGUAGE TypeFamilies #-} {-# OPTIONS_GHC -Wall #-} -- | Action module NumHask.Algebra.Abstract.Action - ( AdditiveAction(..) + ( Actor + , AdditiveAction(..) , SubtractiveAction(..) , MultiplicativeAction(..) , DivisiveAction(..) @@ -12,32 +15,35 @@ module NumHask.Algebra.Abstract.Action import NumHask.Algebra.Abstract.Additive import NumHask.Algebra.Abstract.Multiplicative -class (Additive a) => - AdditiveAction r a where +-- | a type class to represent an action on a higher-kinded number +type family Actor h + +class (Additive (Actor h)) => + AdditiveAction h where infixl 6 .+ - (.+) :: r a -> a -> r a + (.+) :: h -> Actor h -> h infixl 6 +. - (+.) :: a -> r a -> r a + (+.) :: Actor h -> h -> h -class (Subtractive a) => - SubtractiveAction r a where +class (Subtractive (Actor h)) => + SubtractiveAction h where infixl 6 .- - (.-) :: r a -> a -> r a + (.-) :: h -> Actor h -> h infixl 6 -. - (-.) :: a -> r a -> r a + (-.) :: Actor h -> h -> h -class (Multiplicative a) => - MultiplicativeAction r a where +class (Multiplicative (Actor h)) => + MultiplicativeAction h where infixl 7 .* - (.*) :: r a -> a -> r a + (.*) :: h -> Actor h -> h infixl 7 *. - (*.) :: a -> r a -> r a + (*.) :: Actor h -> h -> h -class (Divisive a) => - DivisiveAction r a where +class (Divisive (Actor h)) => + DivisiveAction h where infixl 7 ./ - (./) :: r a -> a -> r a + (./) :: h -> Actor h -> h infixl 7 /. - (/.) :: a -> r a -> r a + (/.) :: Actor h -> h -> h diff --git a/numhask/src/NumHask/Algebra/Abstract/Module.hs b/numhask/src/NumHask/Algebra/Abstract/Module.hs index d155add..15acd70 100644 --- a/numhask/src/NumHask/Algebra/Abstract/Module.hs +++ b/numhask/src/NumHask/Algebra/Abstract/Module.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# OPTIONS_GHC -Wall #-} @@ -19,4 +20,4 @@ import NumHask.Algebra.Abstract.Action -- > c *. (a + b) == (c *. a) + (c *. b) -- > a .* zero == zero -- > a .* b == b *. a -class (Distributive a, Divisive (r a), MultiplicativeAction r a) => Module r a +class (Distributive (Actor h), Divisive h, MultiplicativeAction h) => Module h diff --git a/numhask/src/NumHask/Analysis/Banach.hs b/numhask/src/NumHask/Analysis/Banach.hs index 1edce69..0f78bfe 100644 --- a/numhask/src/NumHask/Analysis/Banach.hs +++ b/numhask/src/NumHask/Analysis/Banach.hs @@ -1,3 +1,5 @@ +{-# LANGUAGE FlexibleContexts #-} +{-# LANGUAGE RankNTypes #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# OPTIONS_GHC -Wall #-} @@ -16,24 +18,21 @@ import NumHask.Analysis.Metric -- | Banach (with Norm) laws form rules around size and direction of a number, with a potential crossing into another codomain. -- -- > a == singleton zero || normalizeL2 a *. normL2 a == a -class (ExpField a, Normed (r a) a, DivisiveAction r a) => - Banach r a where - normalizeL1 :: r a -> r a - normalizeL1 a = a ./ normL1 a +class (ExpField (Actor h), Normed h (Actor h), DivisiveAction h) => + Banach h where + normalizeL1 :: h -> h + normalizeL1 a = a ./ normL1 a - normalizeL2 :: r a -> r a + normalizeL2 :: h -> h normalizeL2 a = a ./ normL2 a - normalizeLp :: a -> r a -> r a - normalizeLp p a = a ./ normLp p a - -- | the inner product: a distributive fold -- -- > a <.> b == b <.> a -- > a <.> (b +c) == a <.> b + a <.> c -- > a <.> (s *. b + c) == s * (a <.> b) + a <.> c -- (s0 *. a) <.> (s1 *. b) == s0 * s1 * (a <.> b) -class (Distributive a) => - Hilbert r a where +class (Distributive (Actor h)) => + Hilbert h where infix 8 <.> - (<.>) :: r a -> r a -> a + (<.>) :: h -> h -> Actor h diff --git a/numhask/src/NumHask/Analysis/Metric.hs b/numhask/src/NumHask/Analysis/Metric.hs index 2025f02..5d73a0e 100644 --- a/numhask/src/NumHask/Analysis/Metric.hs +++ b/numhask/src/NumHask/Analysis/Metric.hs @@ -141,77 +141,62 @@ instance Signed Word64 where class (Additive a, Additive b) => Normed a b where normL1 :: a -> b normL2 :: a -> b - normLp :: b -> a -> b instance Normed Double Double where normL1 = P.abs normL2 = P.abs - normLp _ = P.abs instance Normed Float Float where normL1 = P.abs normL2 = P.abs - normLp _ = P.abs instance Normed Int Int where normL1 = P.abs normL2 = P.abs - normLp _ = P.abs instance Normed Integer Integer where normL1 = P.abs normL2 = P.abs - normLp _ = P.abs instance Normed Natural Natural where normL1 = P.abs normL2 = P.abs - normLp _ = P.abs instance Normed Int8 Int8 where normL1 = P.abs normL2 = P.abs - normLp _ = P.abs instance Normed Int16 Int16 where normL1 = P.abs normL2 = P.abs - normLp _ = P.abs instance Normed Int32 Int32 where normL1 = P.abs normL2 = P.abs - normLp _ = P.abs instance Normed Int64 Int64 where normL1 = P.abs normL2 = P.abs - normLp _ = P.abs instance Normed Word Word where normL1 = P.abs normL2 = P.abs - normLp _ = P.abs instance Normed Word8 Word8 where normL1 = P.abs normL2 = P.abs - normLp _ = P.abs instance Normed Word16 Word16 where normL1 = P.abs normL2 = P.abs - normLp _ = P.abs instance Normed Word32 Word32 where normL1 = P.abs normL2 = P.abs - normLp _ = P.abs instance Normed Word64 Word64 where normL1 = P.abs normL2 = P.abs - normLp _ = P.abs -- | distance between numbers using L1, L2 or Lp-norms -- @@ -223,78 +208,63 @@ instance Normed Word64 Word64 where class Metric a b where distanceL1 :: a -> a -> b distanceL2 :: a -> a -> b - distanceLp :: b -> a -> a -> b instance Metric Double Double where distanceL1 a b = normL1 (a - b) distanceL2 a b = normL2 (a - b) - distanceLp p a b = normLp p (a - b) instance Metric Float Float where distanceL1 a b = normL1 (a - b) distanceL2 a b = normL2 (a - b) - distanceLp p a b = normLp p (a - b) instance Metric Int Int where distanceL1 a b = normL1 (a - b) distanceL2 a b = normL2 (a - b) - distanceLp p a b = normLp p (a - b) instance Metric Integer Integer where distanceL1 a b = normL1 (a - b) distanceL2 a b = normL2 (a - b) - distanceLp p a b = normLp p (a - b) instance Metric Natural Natural where distanceL1 a b = P.fromInteger $ normL1 (P.toInteger a - P.toInteger b) distanceL2 a b = P.fromInteger $ normL2 (P.toInteger a - P.toInteger b) - distanceLp p a b = P.fromInteger (normLp (P.toInteger p) (P.toInteger a - P.toInteger b)) instance Metric Int8 Int8 where distanceL1 a b = normL1 (a - b) distanceL2 a b = normL2 (a - b) - distanceLp p a b = normLp p (a - b) instance Metric Int16 Int16 where distanceL1 a b = normL1 (a - b) distanceL2 a b = normL2 (a - b) - distanceLp p a b = normLp p (a - b) instance Metric Int32 Int32 where distanceL1 a b = normL1 (a - b) distanceL2 a b = normL2 (a - b) - distanceLp p a b = normLp p (a - b) instance Metric Int64 Int64 where distanceL1 a b = normL1 (a - b) distanceL2 a b = normL2 (a - b) - distanceLp p a b = normLp p (a - b) -- fixme: circular distance may be more appropriate instance Metric Word Word where distanceL1 a b = P.fromInteger $ normL1 (P.toInteger a - P.toInteger b) distanceL2 a b = P.fromInteger $ normL2 (P.toInteger a - P.toInteger b) - distanceLp p a b = P.fromInteger (normLp (P.toInteger p) (P.toInteger a - P.toInteger b)) instance Metric Word8 Word8 where distanceL1 a b = P.fromInteger $ normL1 (P.toInteger a - P.toInteger b) distanceL2 a b = P.fromInteger $ normL2 (P.toInteger a - P.toInteger b) - distanceLp p a b = P.fromInteger (normLp (P.toInteger p) (P.toInteger a - P.toInteger b)) instance Metric Word16 Word16 where distanceL1 a b = P.fromInteger $ normL1 (P.toInteger a - P.toInteger b) distanceL2 a b = P.fromInteger $ normL2 (P.toInteger a - P.toInteger b) - distanceLp p a b = P.fromInteger (normLp (P.toInteger p) (P.toInteger a - P.toInteger b)) instance Metric Word32 Word32 where distanceL1 a b = P.fromInteger $ normL1 (P.toInteger a - P.toInteger b) distanceL2 a b = P.fromInteger $ normL2 (P.toInteger a - P.toInteger b) - distanceLp p a b = P.fromInteger (normLp (P.toInteger p) (P.toInteger a - P.toInteger b)) instance Metric Word64 Word64 where distanceL1 a b = P.fromInteger $ normL1 (P.toInteger a - P.toInteger b) distanceL2 a b = P.fromInteger $ normL2 (P.toInteger a - P.toInteger b) - distanceLp p a b = P.fromInteger (normLp (P.toInteger p) (P.toInteger a - P.toInteger b)) class (Eq a, Additive a, Subtractive a, MeetSemiLattice a) => Epsilon a where @@ -340,5 +310,3 @@ instance Epsilon Word16 instance Epsilon Word32 instance Epsilon Word64 - - diff --git a/numhask/src/NumHask/Data/Complex.hs b/numhask/src/NumHask/Data/Complex.hs index e4c74bd..90598a5 100644 --- a/numhask/src/NumHask/Data/Complex.hs +++ b/numhask/src/NumHask/Data/Complex.hs @@ -86,13 +86,11 @@ instance (Multiplicative a, ExpField a, Normed a a) => Normed (Complex a) a where normL1 (rx :+ ix) = normL1 rx + normL1 ix normL2 (rx :+ ix) = sqrt (rx * rx + ix * ix) - normLp p (rx :+ ix) = (normL1 rx ** p + normL1 ix ** p) ** (one / p) instance (Multiplicative a, Subtractive a, ExpField a, Normed a a) => Metric (Complex a) a where distanceL1 a b = normL1 (a - b) distanceL2 a b = normL2 (a - b) - distanceLp p a b = normLp p (a - b) instance (Ord a, Signed a, Subtractive a, Epsilon a) => Epsilon (Complex a) where diff --git a/numhask/src/NumHask/Data/Pair.hs b/numhask/src/NumHask/Data/Pair.hs index 0151c0e..3d46498 100644 --- a/numhask/src/NumHask/Data/Pair.hs +++ b/numhask/src/NumHask/Data/Pair.hs @@ -110,6 +110,8 @@ instance (Bounded a) => Bounded (Pair a) where minBound = Pair minBound minBound maxBound = Pair maxBound maxBound +unaryOp :: (a -> a) -> (Pair a -> Pair a) +unaryOp f (Pair a b) = Pair (f a) (f b) binOp :: (a -> a -> a) -> (Pair a -> Pair a -> Pair a) binOp (#) (Pair a0 b0) (Pair a1 b1) = Pair (a0 # a1) (b0 # b1) @@ -120,14 +122,14 @@ instance (Additive a) => Additive (Pair a) where zero = Pair zero zero instance (Subtractive a) => Subtractive (Pair a) where - negate (Pair a b) = Pair (negate a) (negate b) + negate = unaryOp negate instance (Multiplicative a) => Multiplicative (Pair a) where (Pair a0 b0) * (Pair a1 b1) = Pair (a0 * a1) (b0 * b1) one = Pair one one instance (Divisive a) => Divisive (Pair a) where - recip (Pair a b) = Pair (recip a) (recip b) + recip = unaryOp recip instance (Integral a) => Integral (Pair a) where (Pair a0 b0) `divMod` (Pair a1 b1) = (Pair da db, Pair ma mb) @@ -140,14 +142,13 @@ instance (Integral a) => Integral (Pair a) where (db, mb) = b0 `quotRem` b1 instance (Signed a) => Signed (Pair a) where - sign (Pair a b) = Pair (sign a) (sign b) - abs (Pair a b) = Pair (abs a) (abs b) + sign = unaryOp sign + abs = unaryOp abs instance (ExpField a, Normed a a) => Normed (Pair a) a where normL1 (Pair a b) = normL1 a + normL1 b normL2 (Pair a b) = sqrt (a ** (one + one) + b ** (one + one)) - normLp p (Pair a b) = (normL1 a ** p + normL1 b ** p) ** (one/p) instance (Subtractive a, Epsilon a) => Epsilon (Pair a) where epsilon = Pair epsilon epsilon @@ -156,7 +157,6 @@ instance (Subtractive a, Epsilon a) => Epsilon (Pair a) where instance (ExpField a, Subtractive a, Normed a a) => Metric (Pair a) a where distanceL1 a b = normL1 (a - b) distanceL2 a b = normL2 (a - b) - distanceLp p a b = normLp p (a - b) instance (Distributive a) => Distributive (Pair a) @@ -164,8 +164,8 @@ instance (Field a) => Field (Pair a) instance (IntegralDomain a) => IntegralDomain (Pair a) instance (ExpField a) => ExpField (Pair a) where - exp (Pair a b) = Pair (exp a) (exp b) - log (Pair a b) = Pair (log a) (log b) + exp = unaryOp exp + log = unaryOp log instance (UpperBoundedField a) => UpperBoundedField (Pair a) where @@ -173,24 +173,26 @@ instance (UpperBoundedField a) => UpperBoundedField (Pair a) instance (LowerBoundedField a) => LowerBoundedField (Pair a) -instance (Additive a) => AdditiveAction Pair a where +type instance Actor (Pair a) = a + +instance (Additive a) => AdditiveAction (Pair a) where (.+) r s = fmap (s+) r (+.) s r = fmap (s+) r -instance (Subtractive a) => SubtractiveAction Pair a where +instance (Subtractive a) => SubtractiveAction (Pair a) where (.-) r s = fmap (\x -> x - s) r (-.) s r = fmap (\x -> x - s) r -instance (Multiplicative a) => MultiplicativeAction Pair a where +instance (Multiplicative a) => MultiplicativeAction (Pair a) where (.*) r s = fmap (s*) r (*.) s r = fmap (s*) r -instance (Divisive a) => DivisiveAction Pair a where +instance (Divisive a) => DivisiveAction (Pair a) where (./) r s = fmap (/ s) r (/.) s r = fmap (/ s) r instance (JoinSemiLattice a) => JoinSemiLattice (Pair a) where - (\/) (Pair ax ay) (Pair bx by) = Pair (ax \/ bx) (ay \/ by) + (\/) = binOp (\/) instance (MeetSemiLattice a) => MeetSemiLattice (Pair a) where - (/\) (Pair ax ay) (Pair bx by) = Pair (ax /\ bx) (ay /\ by) + (/\) = binOp (/\) instance (BoundedJoinSemiLattice a) => BoundedJoinSemiLattice (Pair a) where bottom = Pair bottom bottom @@ -208,10 +210,8 @@ instance (Normed a a) => Normed (Pair a) (Pair a) where normL1 = fmap normL1 normL2 = fmap normL2 - normLp = binOp normLp instance (Subtractive a, Normed a a) => Metric (Pair a) (Pair a) where distanceL1 a b = normL1 (a - b) distanceL2 a b = normL2 (a - b) - distanceLp p a b = normLp p (a - b) diff --git a/numhask/src/NumHask/Data/Positive.hs b/numhask/src/NumHask/Data/Positive.hs index 0344462..33abde8 100644 --- a/numhask/src/NumHask/Data/Positive.hs +++ b/numhask/src/NumHask/Data/Positive.hs @@ -77,9 +77,7 @@ instance (Normed a a) => Normed a (Positive a) where normL1 a = Positive (normL1 a) normL2 a = Positive (normL2 a) - normLp (Positive p) a = Positive (normLp p a) instance (Subtractive a, Normed a a) => Metric a (Positive a) where distanceL1 a b = Positive P.$ normL1 (a - b) distanceL2 a b = Positive P.$ normL2 (a - b) - distanceLp (Positive p) a b = Positive P.$ normLp p (a - b) diff --git a/numhask/src/NumHask/Data/Rational.hs b/numhask/src/NumHask/Data/Rational.hs index bf1fdd6..c54538f 100644 --- a/numhask/src/NumHask/Data/Rational.hs +++ b/numhask/src/NumHask/Data/Rational.hs @@ -105,12 +105,10 @@ instance (GCDConstraints a) => Signed (Ratio a) where instance (GCDConstraints a) => Normed (Ratio a) (Ratio a) where normL1 = abs normL2 = abs - normLp _ = abs instance (GCDConstraints a) => Metric (Ratio a) (Ratio a) where distanceL1 a b = normL1 (a - b) distanceL2 a b = normL2 (a - b) - distanceLp p a b = normLp p (a - b) instance (GCDConstraints a, MeetSemiLattice a) => Epsilon (Ratio a) From 4beb5d3eb073ef362792ef03ea7182f832ddf6d7 Mon Sep 17 00:00:00 2001 From: Tony Day Date: Wed, 12 Sep 2018 11:06:35 +1000 Subject: [PATCH 09/10] removed separate package compiles --- .travis.yml | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8d93d50..a9203a1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,16 +20,9 @@ ghc: # - 8.6.1 - 8.4.3 -env: - - PACKAGEDIR="numhask" - - PACKAGEDIR="numhask-prelude" - - PACKAGEDIR="numhask-array" - - PACKAGEDIR="numhask-hedgehog" - matrix: allow_failures: - ghc: head - - ghc: ghc-8.6.1 # Ensure necessary system libraries are present addons: @@ -41,9 +34,6 @@ addons: - cabal-install-2.2 # required by GHC 8.* - cabal-install-head # required by GHC head -before_install: - - cd ${PACKAGEDIR} - install: # Download and unpack the stack executable - mkdir -p ~/.local/bin From 97850e9fcc0d7cc5652c9b6f8d98c390d475f8c1 Mon Sep 17 00:00:00 2001 From: Tony Day Date: Thu, 14 Mar 2019 09:59:02 +1000 Subject: [PATCH 10/10] fixed gridSensible and added fromList to Prelude --- .travis.yml | 1 - numhask-prelude/numhask-prelude.cabal | 2 +- numhask-prelude/src/NumHask/Prelude.hs | 1 + numhask-space/numhask-space.cabal | 2 +- numhask-space/src/NumHask/Data/Range.hs | 13 +++++++------ 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index a9203a1..c367c8c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,6 @@ # https://github.com/ekmett/intervals/blob/master/.travis.yml sudo: true - language: haskell # Caching so the next build will be fast too. diff --git a/numhask-prelude/numhask-prelude.cabal b/numhask-prelude/numhask-prelude.cabal index 763020f..3f892ca 100644 --- a/numhask-prelude/numhask-prelude.cabal +++ b/numhask-prelude/numhask-prelude.cabal @@ -1,5 +1,5 @@ name: numhask-prelude -version: 0.3 +version: 0.3.1 synopsis: A numeric prelude description: diff --git a/numhask-prelude/src/NumHask/Prelude.hs b/numhask-prelude/src/NumHask/Prelude.hs index 32a8087..4e85850 100644 --- a/numhask-prelude/src/NumHask/Prelude.hs +++ b/numhask-prelude/src/NumHask/Prelude.hs @@ -14,6 +14,7 @@ module NumHask.Prelude , fromString , fail , ifThenElse + , fromList , fromListN -- * Algebraic Heirarchy -- $instances diff --git a/numhask-space/numhask-space.cabal b/numhask-space/numhask-space.cabal index 722c638..2148e12 100644 --- a/numhask-space/numhask-space.cabal +++ b/numhask-space/numhask-space.cabal @@ -1,5 +1,5 @@ name: numhask-space -version: 0.1 +version: 0.1.1 synopsis: numerical spaces description: diff --git a/numhask-space/src/NumHask/Data/Range.hs b/numhask-space/src/NumHask/Data/Range.hs index 9597d84..4e1dae6 100644 --- a/numhask-space/src/NumHask/Data/Range.hs +++ b/numhask-space/src/NumHask/Data/Range.hs @@ -34,7 +34,7 @@ import NumHask.Analysis.Metric import NumHask.Analysis.Space as S import NumHask.Data.Integral import NumHask.Data.Rational -import Prelude (Eq(..), Ord(..), Show(..), Integer, Bool(..), Foldable(..), Functor, Traversable(..), Applicative, pure, (<*>), (.), otherwise, (&&), fmap, (<$>), Semigroup(..), Monoid(..), zipWith, drop) +import Prelude (Eq(..), Ord(..), Show(..), Integer, Bool(..), Foldable(..), Functor, Traversable(..), Applicative, pure, (<*>), (.), otherwise, (&&), fmap, (<$>), Semigroup(..), Monoid(..), zipWith, drop, filter, ($), id) -- $setup -- >>> :set -XNoImplicitPrelude @@ -239,16 +239,17 @@ stepSensible tp span n = | err <= 0.75 = 2.0 * step' | otherwise = step' -gridSensible :: (Ord a, FromInteger a, FromRatio a, QuotientField a Integer, ExpField a) => - Pos -> Range a -> Integer -> [a] -gridSensible tp (Range l u) n = +gridSensible :: (Ord a, JoinSemiLattice a, FromInteger a, FromRatio a, QuotientField a Integer, ExpField a, Epsilon a) => + Pos -> Bool -> Range a -> Integer -> [a] +gridSensible tp inside r@(Range l u) n = + bool id (filter (`memberOf` r)) inside $ (+ bool zero (step/two) (tp==MidPos)) <$> posns where posns = (first' +) . (step *) . fromIntegral <$> [i0..i1] span = u - l step = stepSensible tp span n - first' = step * fromIntegral (ceiling (l/step) :: Integer) - last' = step * fromIntegral (floor (u/step) :: Integer) + first' = step * fromIntegral (floor (l/step + epsilon) :: Integer) + last' = step * fromIntegral (ceiling (u/step - epsilon) :: Integer) n' = round ((last' - first')/step) (i0,i1) = case tp of OuterPos -> (0::Integer,n')