on master help sign in
.ghc.environment.x86_64-linux-8.6.5deleted−17
since splitsnapshots
unifiedsplit
@@ -1,17 +0,0 @@
1−-- This is a GHC environment file written by cabal. This means you can
2−-- run ghc or ghci and get the environment of the project as a whole.
3−-- But you still need to use cabal repl $target to get the environment
4−-- of specific components (libs, exes, tests etc) because each one can
5−-- have its own source dirs, cpp flags etc.
6−--
7−clear-package-db
8−global-package-db
9−package-db /home/bolt/.cabal/store/ghc-8.6.5/package.db
10−package-db packagedb/ghc-8.6.5
11−package-id laop-0.1.0.0-inplace
12−package-id base-4.12.0.0
13−package-id ghc-prim-0.5.3
14−package-id rts
15−package-id integer-gmp-1.0.2.0
16−package-id deepseq-1.4.4.0
17−package-id array-0.5.3.0
.ghc.environment.x86_64-linux-8.8.3deleted−17
@@ -1,17 +0,0 @@
1−-- This is a GHC environment file written by cabal. This means you can
2−-- run ghc or ghci and get the environment of the project as a whole.
3−-- But you still need to use cabal repl $target to get the environment
4−-- of specific components (libs, exes, tests etc) because each one can
5−-- have its own source dirs, cpp flags etc.
6−--
7−clear-package-db
8−global-package-db
9−package-db /home/bolt/.cabal/store/ghc-8.8.3/package.db
10−package-db dist-docs.Q1TJPL/packagedb/ghc-8.8.3
11−package-id laop-0.1.0.7-inplace
12−package-id base-4.13.0.0
13−package-id ghc-prim-0.5.3
14−package-id rts
15−package-id integer-gmp-1.0.2.0
16−package-id deepseq-1.4.4.0
17−package-id array-0.5.4.0
.github/workflows/ci.ymlnew file+43
@@ -0,0 +1,43 @@
1+name: CI
2+
3+# Trigger the workflow on push or pull request, but only for the master branch
4+on:
5+ pull_request:
6+ push:
7+ branches: [master]
8+
9+jobs:
10+ build:
11+ name: ghc ${{ matrix.ghc }}
12+ runs-on: ubuntu-16.04
13+ strategy:
14+ matrix:
15+ cabal: ["3.0"]
16+ ghc:
17+ - "8.6.5"
18+ - "8.8.3"
19+
20+ steps:
21+ - uses: actions/checkout@v2
22+ if: github.event.action == 'opened' || github.event.action == 'synchronize' || github.event.ref == 'refs/heads/master'
23+
24+ - uses: actions/setup-haskell@v1
25+ name: Setup Haskell
26+ with:
27+ ghc-version: ${{ matrix.ghc }}
28+ cabal-version: ${{ matrix.cabal }}
29+
30+ - uses: actions/cache@v1
31+ name: Cache ~/.cabal/store
32+ with:
33+ path: ~/.cabal/store
34+ key: ${{ runner.os }}-${{ matrix.ghc }}-cabal
35+
36+ - name: Build
37+ run: |
38+ cabal v2-update
39+ cabal v2-build --enable-tests --enable-benchmarks
40+
41+ - name: Test
42+ run: |
43+ cabal v2-test --enable-tests
.gitignore+54−2
@@ -1,3 +1,55 @@
1+### Haskell
2+dist
3+dist-*
4+cabal-dev
5+*.o
6+*.hi
7+*.chi
8+*.chs.h
9+*.dyn_o
10+*.dyn_hi
11+*.prof
12+*.aux
13+*.hp
14+*.eventlog
15+.virtualenv
16+.hsenv
17+.hpc
18+.cabal-sandbox/
19+cabal.sandbox.config
20+cabal.config
21+cabal.project.local
22+.ghc.environment.*
23+.HTF/
24+# Stack
1.stack-work/
25.stack-work/
2−laop.cabal
26+stack.yaml.lock
27+
28+### IDE/support
29+# Vim
30+[._]*.s[a-v][a-z]
31+[._]*.sw[a-p]
32+[._]s[a-v][a-z]
33+[._]sw[a-p]
3−*~
34+*~
35+tags
36+
37+# IntellijIDEA
38+.idea/
39+.ideaHaskellLib/
40+*.iml
41+
42+# Atom
43+.haskell-ghc-mod.json
44+
45+# VS
46+.vscode/
47+
48+# Emacs
49+*#
50+.dir-locals.el
51+TAGS
52+
53+# other
54+.DS_Store
55+hackage.sh
.travis.ymlnew file+47
@@ -0,0 +1,47 @@
1+sudo: true
2+language: haskell
3+
4+git:
5+ depth: 5
6+
7+cabal: "3.0"
8+
9+cache:
10+ directories:
11+ - "$HOME/.cabal/store"
12+ - "$HOME/.stack"
13+ - "$TRAVIS_BUILD_DIR/.stack-work"
14+
15+matrix:
16+ include:
17+ - ghc: 8.6.5
18+ - ghc: 8.8.3
19+
20+ - ghc: 8.8.3
21+ env: STACK_YAML="$TRAVIS_BUILD_DIR/stack-8.8.3.yaml"
22+
23+ - ghc: 8.6.5
24+ env: STACK_YAML="$TRAVIS_BUILD_DIR/stack.yaml"
25+
26+
27+install:
28+ - |
29+ if [ -z "$STACK_YAML" ]; then
30+ cabal v2-update
31+ cabal v2-build --enable-tests --enable-benchmarks
32+ else
33+ curl -sSL https://get.haskellstack.org/ | sh
34+ stack --version
35+ stack build --system-ghc --test --bench --no-run-tests --no-run-benchmarks
36+ fi
37+
38+script:
39+ - |
40+ if [ -z "$STACK_YAML" ]; then
41+ cabal v2-test --enable-tests
42+ else
43+ stack test --system-ghc
44+ fi
45+
46+notifications:
47+ email: false
CHANGELOG.mdnew file+17
@@ -0,0 +1,17 @@
1+# Changelog
2+
3+`laop` uses [PVP Versioning][1].
4+The changelog is available [on GitHub][2].
5+
6+## 0.1.1.1
7+
8+* Bump base version to work with cabal
9+
10+## 0.1.1.0
11+
12+* Package is more organized and now has tests and benchmarks separated
13+* Repository is more organized and clean
14+* Added CI
15+
16+[1]: https://pvp.haskell.org
17+[2]: https://github.com/bolt12/laop2/releases
ChangeLog.mddeleted−3
@@ -1,3 +0,0 @@
1−# Changelog for laop
2−
3−## Unreleased changes
LICENSE+17−26
@@ -1,30 +1,21 @@
1−Copyright Armando Santos (c) 2019
1+MIT License
2
2
3−All rights reserved.
3+Copyright (c) 2020 Armando Santos
4
4
5−Redistribution and use in source and binary forms, with or without
5+Permission is hereby granted, free of charge, to any person obtaining a copy
6+of this software and associated documentation files (the "Software"), to deal
7+in the Software without restriction, including without limitation the rights
8+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+copies of the Software, and to permit persons to whom the Software is
6−modification, are permitted provided that the following conditions are met:
10+furnished to do so, subject to the following conditions:
7
11
8− * Redistributions of source code must retain the above copyright
12+The above copyright notice and this permission notice shall be included in all
9− notice, this list of conditions and the following disclaimer.
13+copies or substantial portions of the Software.
10
14
11− * Redistributions in binary form must reproduce the above
15+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12− copyright notice, this list of conditions and the following
13− disclaimer in the documentation and/or other materials provided
14− with the distribution.
15−
16− * Neither the name of Armando Santos nor the names of other
17− contributors may be used to endorse or promote products derived
18− from this software without specific prior written permission.
19−
20−THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21−"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22−LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
16+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23−A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
17+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24−OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
18+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25−SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26−LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27−DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28−THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
19+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29−(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
20+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30−OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
21+SOFTWARE.
README.md+34−30
@@ -1,5 +1,11 @@
1# laop - Linear Algebra of Programming library
1# laop - Linear Algebra of Programming library
2
2
3+[![GitHub CI](https://github.com/bolt12/laop/workflows/CI/badge.svg)](https://github.com/bolt12/laop/actions)
4+[![Build status](https://img.shields.io/travis/bolt12/laop.svg?logo=travis)](https://travis-ci.org/bolt12/laop)
5+[![Hackage](https://img.shields.io/hackage/v/laop.svg?logo=haskell)](https://hackage.haskell.org/package/laop)
6+[![Stackage Lts](http://stackage.org/package/laop/badge/lts)](http://stackage.org/lts/package/laop)
7+[![Stackage Nightly](http://stackage.org/package/laop/badge/nightly)](http://stackage.org/nightly/package/laop)
8+
3The LAoP discipline generalises relations and functions treating them as
9The LAoP discipline generalises relations and functions treating them as
4Boolean matrices and in turn consider these as arrows.
10Boolean matrices and in turn consider these as arrows.
5
11
@@ -10,40 +16,38 @@ motivation behind the library, the underlying theory, and implementation details
10This module offers many of the combinators mentioned in the work of
16This module offers many of the combinators mentioned in the work of
11[Macedo (2012)](https://repositorium.sdum.uminho.pt/handle/1822/22894) and [Oliveira (2012)](https://pdfs.semanticscholar.org/ccf5/27fa9179081223bffe8067edd81948644fc0.pdf).
17[Macedo (2012)](https://repositorium.sdum.uminho.pt/handle/1822/22894) and [Oliveira (2012)](https://pdfs.semanticscholar.org/ccf5/27fa9179081223bffe8067edd81948644fc0.pdf).
12
18
13−See the package in hackage [here](https://hackage.haskell.org/package/laop-0.1.0.5)
19+See the package in hackage [here](https://hackage.haskell.org/package/laop-0.1.1.0)
14−
15−There are a couple of repos with a WIP of benchmarks comparing [matrix composition](https://github.com/bolt12/laop-benchmarks) and a real use case of [data analytics](https://github.com/bolt12/laop-analytics).
16
20
17−A Functional Pearl is also on its way, hopefully will be the reference document for this library.
21+A Functional Pearl has been written and can be regarded as the [reference document](https://github.com/bolt12/tymfgg-pearl) for this library.
18
22
19## Features
23## Features
20
24
21−This library offers:
25+This library offers 3 main matrix programming modules:
22−
26+
23−- An internal module representation that uses normal datatypes (`Void`, `()`, `Either`) for matrix dimensions and two
27+- One in which matrices are typed with type level natural numbers;
24− type families `FromNat` and `Count` to make it easier to work with these type of matrices.
28+- One in which matrices are typed with arbitrary generic data types;
25−- An interfacing module that uses generalised types for the dimensions and is just a newtype wrapper
29+- One in which matrices are regarded as relations, i.e. boolean matrices;
26− around the internal matrix data type.
30+
27−- An interfacing module that uses type level naturals for the dimensions and is just a newtype wrapper
31+There's also an experimental module that uses matrices to represent probability
28− around the internal matrix data type.
32+distributions.
29−- An interfacing module that restricts the matrix contents to being only 0's or 1's (True
33+
30− and False). This module is called 'Relation' and offers many of the combinators seen in
34+The most interesting feature is that matrices are represented as an inductive data type.
31− AoP and Relational Calculus/Algebra.
35+Given this formulation, matrix algorithms can be expressed in a much more elegant and
32−- A very simple Probabilistic Programming module and several functions and data types to
36+calculational style than the traditional vector of vectors representation. This data type
33− make it easier to deal with sample space.
37+guarantees that a matrix will always have valid dimensions. It can also express block matrix
34−
38+computations naturally, which leads to total, efficient and statically typed manipulation
35−Given this, this new matrix formulation compared to other libraries one has much more advantages, such as:
39+and transformation functions.
36−
40+
37−- Has an inductive definition enabling writing matrix manipulation functions in a much more elegant and calculational way;
41+Like matrix multiplication, other common operations, such as matrix transposition, benefit from a block-oriented structure that leads to a simple and natural divide-and-conquer algorithmic solution. Performance wise, this means that without much effort we can obtain optimal cache-oblivious algorithms.
38−- Statically typed dimensions;
42+
39−- Polymorphic data type dimensions;
43+Given this, this new matrix formulation compared to other libraries:
40−- Polymorphic matrix content;
44+
41−- Awesome dimension type inference;
45+- Is more compositional and polymorphic and does not have partial matrix manipulation functions (hence less chances for usage errors);
42−- Fast type natural conversion via `FromNat` type family;
46+- Our implementation of matrices enables simple manipulation of submatrices, making it particularly suitable for formal verification and equation reasoning, using the mathematical framework defined by the linear algebra of programming. Furthermore, the data type constructors ensure that the matrices of this kind are sound, i.e. malformed matrices with incorrect dimensions of the sort, can not be constructed.
43−- Matrix `Junc` and `Split`-ing in O(1);
47+
44−- Matrix composition takes advantage of divide-and-conquer and fusion laws.
48+## Known issues
45−
49+
46−Unfortunately, this approach does not solve the issue of type dimensions being in some way constrainted making it impossible to write Arrow instances, for example. Type inference isn't perfect, when it comes to infer the types of matrices which dimensions are computed using type level naturals multiplication, the compiler needs type annotations in order to succeed.
50+Unfortunately, due to the use of type-level programming features, this approach sometimes requires type dimensions to be constrainted, in some way, impossible to write idiomatic Arrow instances, for example. Type inference isn't perfect, when it comes to infer the types of matrices which dimensions are computed using type level naturals multiplication, the compiler needs type annotations in order to succeed. And not all kinds of programs can be modeled using matrices, namely programs that deal with arbitrary infinite data types such as lists or integers (although there are some workarounds).
47
51
48## Notes
52## Notes
49
53
Setup.hsdeleted−2
@@ -1,2 +0,0 @@
1−import Distribution.Simple
2−main = defaultMain
app/Main.hsdeleted−7
@@ -1,7 +0,0 @@
1−module Main where
2−
3−import Examples
4−import Benchmarks
5−
6−main :: IO ()
7−main = benchmark
appveyor.ymlnew file+34
@@ -0,0 +1,34 @@
1+clone_folder: "c:\\WORK"
2+clone_depth: 5
3+
4+# Do not build feature branch with open Pull Requests
5+skip_branch_with_pr: true
6+
7+platform:
8+ - x86_64
9+
10+cache:
11+ - "C:\\SR"
12+ - dist-newstyle
13+
14+environment:
15+ global:
16+ CABOPTS: --store-dir=C:\\SR
17+
18+ matrix:
19+ - GHCVER: 8.6.5
20+
21+install:
22+ - choco source add -n mistuke -s https://www.myget.org/F/mistuke/api/v2
23+ - choco install -y cabal --version 2.4.1.0
24+ - choco install -y ghc --version 8.6.3
25+ - refreshenv
26+
27+before_build:
28+ - cabal --version
29+ - ghc --version
30+ - cabal %CABOPTS% v2-update
31+
32+build_script:
33+ - cabal %CABOPTS% v2-build --enable-tests
34+ - cabal %CABOPTS% v2-test --enable-tests
app/Benchmarks.hs → benchmark/Main.hsrenamed+3−6
@@ -8,10 +8,7 @@
8{-# LANGUAGE AllowAmbiguousTypes #-}
8{-# LANGUAGE AllowAmbiguousTypes #-}
9{-# LANGUAGE ScopedTypeVariables #-}
9{-# LANGUAGE ScopedTypeVariables #-}
10
10
11−module Benchmarks
12− ( benchmark
13− )
14− where
11+module Main (main) where
15
12
16import LAoP.Dist.Internal
13import LAoP.Dist.Internal
17import LAoP.Utils
14import LAoP.Utils
@@ -147,8 +144,8 @@ setupEnv2 = do
147 distList2 <- generate (resize 1 (randomDistF @(Natural 0 100) @(Natural 0 100)))
144 distList2 <- generate (resize 1 (randomDistF @(Natural 0 100) @(Natural 0 100)))
148 return (m21, m40, dist, dist2, distList1, distList2)
145 return (m21, m40, dist, dist2, distList1, distList2)
149
146
150−benchmark :: IO ()
147+main :: IO ()
151−benchmark = defaultMain [
148+main = defaultMain [
152 env setupEnv $ \ ~(m11, m12, m21, m22, m31, m32) -> bgroup "Matrix Composition" [
149 env setupEnv $ \ ~(m11, m12, m21, m22, m31, m32) -> bgroup "Matrix Composition" [
153 bgroup "10x10" [
150 bgroup "10x10" [
154 bench "WHNF - 10x10" $ whnf (comp m11) m12
151 bench "WHNF - 10x10" $ whnf (comp m11) m12
hackage.shdeleted−10
@@ -1,10 +0,0 @@
1−#!/bin/sh
2−set -e
3−
4−dir=$(mktemp -d dist-docs.XXXXXX)
5−trap 'rm -r "$dir"' EXIT
6−
7−# assumes cabal 2.4 or later
8−cabal v2-haddock --builddir="$dir" --haddock-for-hackage --enable-doc
9−
10−cabal upload -d $dir/*-docs.tar.gz --publish
laop.cabal+82−72
@@ -1,79 +1,89 @@
1−cabal-version: 1.12
1+cabal-version: 2.4
2+name: laop
3+version: 0.1.1.1
4+synopsis: Matrix programming library
5+description: Matrix programming library that uses a type-safe inductive definition
6+ inspired by the Linear Algebra of Programming
7+homepage: https://github.com/bolt12/laop
8+bug-reports: https://github.com/bolt12/laop/issues
9+license: MIT
10+license-file: LICENSE
11+author: Armando Santos
12+maintainer: Armando Santos <armandoifsantos@gmail.com>
13+copyright: 2020 Armando Santos
14+category: Data
15+build-type: Simple
16+extra-doc-files: README.md
17+ CHANGELOG.md
18+tested-with: GHC == 8.6.5
19+ GHC == 8.8.3
2
20
3−-- This file has been generated from package.yaml by hpack version 0.31.2.
21+source-repository head
4−--
22+ type: git
5−-- see: https://github.com/sol/hpack
23+ location: https://github.com/bolt12/laop.git
6−--
7−-- hash: c53e5ac8b0734f570fcea8d217d84e401323172c60a00eee9d60ffbaef505191
8
24
9−name: laop
25+common common-options
10−version: 0.1.0.7
26+ build-depends: base >= 4.12.0.0 && < 5,
11−description: Please see the README on GitHub at <https://github.com/xxxx/laop#readme>
27+ deepseq
12−category: Data
28+
13−homepage: https://github.com/xxxx/laop#readme
29+ ghc-options: -Wall
14−bug-reports: https://github.com/xxxx/laop/issues
30+ -Wcompat
15−author: Armando Santos
31+ -Widentities
16−maintainer: armandoifsantos@gmail.com
32+ -Wincomplete-uni-patterns
17−copyright: MIT
33+ -Wincomplete-record-updates
18−license: BSD3
34+ if impl(ghc >= 8.0)
19−license-file: LICENSE
35+ ghc-options: -Wredundant-constraints
20−build-type: Simple
36+ if impl(ghc >= 8.2)
21−extra-source-files:
37+ ghc-options: -fhide-source-paths
22− README.md
38+ if impl(ghc >= 8.4)
23− ChangeLog.md
39+ ghc-options: -Wmissing-export-lists
40+ -Wpartial-fields
41+ if impl(ghc >= 8.8)
42+ ghc-options: -Wmissing-deriving-strategies
24
43
25−source-repository head
44+ default-language: Haskell2010
26− type: git
27− location: https://github.com/xxxx/laop
28
45
29library
46library
47+ import: common-options
48+ hs-source-dirs: src
30− exposed-modules:
49+ exposed-modules: LAoP.Dist
31− LAoP.Dist
32− LAoP.Dist.Internal
50+ LAoP.Dist.Internal
33− LAoP.Matrix.Internal
51+ LAoP.Matrix.Internal
34− LAoP.Matrix.Nat
52+ LAoP.Matrix.Nat
35− LAoP.Matrix.Type
53+ LAoP.Matrix.Type
36− LAoP.Relation
54+ LAoP.Relation
37− LAoP.Relation.Internal
55+ LAoP.Relation.Internal
38− LAoP.Utils
56+ LAoP.Utils
39− LAoP.Utils.Internal
57+ LAoP.Utils.Internal
40− other-modules:
41− Paths_laop
42− hs-source-dirs:
43− src
44− build-depends:
45− base >=4.7 && <5
46− , deepseq
47− default-language: Haskell2010
48−
49−executable laop-exe
50− main-is: Main.hs
51− other-modules:
52− Benchmarks
53− Examples
54− Spreadsheets
55− Paths_laop
56− hs-source-dirs:
57− app
58− ghc-options: -threaded -rtsopts -with-rtsopts=-N2 -funfolding-use-threshold=16 -fexcess-precision -optc-O3 -optc-ffast-math
59− build-depends:
60− QuickCheck
61− , base >=4.7 && <5
62− , criterion
63− , deepseq
64− , laop
65− default-language: Haskell2010
66
58
67test-suite laop-test
59test-suite laop-test
60+ import: common-options
68− type: exitcode-stdio-1.0
61+ type: exitcode-stdio-1.0
69− main-is: Spec.hs
62+ hs-source-dirs: test
70− other-modules:
63+ other-modules: Examples.Readme
71− Paths_laop
64+ main-is: Spec.hs
72− hs-source-dirs:
65+ build-depends: laop
73− test
74− ghc-options: -threaded -rtsopts -with-rtsopts=-N
66+ ghc-options: -threaded
67+ -rtsopts
68+ -with-rtsopts=-N
69+ -funfolding-use-threshold=16
70+ -fexcess-precision
71+ -optc-O3
72+ -optc-ffast-math
73+
74+benchmark laop-benchmark
75+ import: common-options
76+ type: exitcode-stdio-1.0
77+ hs-source-dirs: benchmark
78+ main-is: Main.hs
75− build-depends:
79+ build-depends: criterion
76− base >=4.7 && <5
80+ , QuickCheck
77− , deepseq
81+ , deepseq
78− , laop
82+ , laop
79− default-language: Haskell2010
83+ ghc-options: -threaded
84+ -rtsopts
85+ -with-rtsopts=-N
86+ -funfolding-use-threshold=16
87+ -fexcess-precision
88+ -optc-O3
89+ -optc-ffast-math
package.yamldeleted−57
@@ -1,57 +0,0 @@
1−name: laop
2−version: 0.1.0.7
3−github: "bolt12/laop"
4−license: BSD3
5−author: "Armando Santos"
6−maintainer: "armandoifsantos@gmail.com"
7−copyright: "MIT"
8−
9−extra-source-files:
10−- README.md
11−- ChangeLog.md
12−
13−# Metadata used when publishing your package
14−# synopsis: Short description of your package
15−category: Data
16−
17−# To avoid duplicated efforts in documentation and dealing with the
18−# complications of embedding Haddock markup inside cabal files, it is
19−# common to point users to the README.md file.
20−description: Please see the README on GitHub at <https://github.com/bolt12/laop#readme>
21−
22−dependencies:
23−- base >= 4.7 && < 5
24−- deepseq
25−
26−library:
27− source-dirs: src
28−
29−executables:
30− laop-exe:
31− main: Main.hs
32− source-dirs: app
33− ghc-options:
34− - -threaded
35− - -rtsopts
36− - -with-rtsopts=-N
37− - -funfolding-use-threshold=16
38− - -fexcess-precision # Good for doubles
39− - -optc-O3 # Good for doubles
40− - -optc-ffast-math # Good for doubles
41− - -O2
42− dependencies:
43− - laop
44− - criterion
45− - deepseq
46− - QuickCheck
47−
48−tests:
49− laop-test:
50− main: Spec.hs
51− source-dirs: test
52− ghc-options:
53− - -threaded
54− - -rtsopts
55− - -with-rtsopts=-N
56− dependencies:
57− - laop
src/LAoP/Matrix/Internal.hs+54−87
@@ -30,7 +30,7 @@
30-- motivation behind the library, the underlying theory, and implementation details.
30-- motivation behind the library, the underlying theory, and implementation details.
31--
31--
32-- This module offers many of the combinators mentioned in the work of
32-- This module offers many of the combinators mentioned in the work of
33−-- Macedo (2012) and Oliveira (2012).
33+-- Macedo (2012) and Oliveira (2012).
34--
34--
35-- This is an Internal module and it is no supposed to be imported.
35-- This is an Internal module and it is no supposed to be imported.
36--
36--
@@ -43,8 +43,8 @@ module LAoP.Matrix.Internal
43 --
43 --
44 -- There exists two type families that make it easier to write
44 -- There exists two type families that make it easier to write
45 -- matrix dimensions: 'FromNat' and 'Count'. This approach
45 -- matrix dimensions: 'FromNat' and 'Count'. This approach
46− -- leads to a very straightforward implementation
46+ -- leads to a very straightforward implementation
47− -- of LAoP combinators.
47+ -- of LAoP combinators.
48
48
49 -- * Type safe matrix representation
49 -- * Type safe matrix representation
50 Matrix (..),
50 Matrix (..),
@@ -86,7 +86,9 @@ module LAoP.Matrix.Internal
86 -- * Misc
86 -- * Misc
87 -- ** Get dimensions
87 -- ** Get dimensions
88 columns,
88 columns,
89+ columns',
89 rows,
90 rows,
91+ rows',
90
92
91 -- ** Matrix Transposition
93 -- ** Matrix Transposition
92 tr,
94 tr,
@@ -174,6 +176,7 @@ import Data.Kind
174import Data.List
176import Data.List
175import Data.Maybe
177import Data.Maybe
176import Data.Proxy
178import Data.Proxy
179+import Data.Typeable
177import Data.Void
180import Data.Void
178import GHC.TypeLits
181import GHC.TypeLits
179import Data.Type.Equality
182import Data.Type.Equality
@@ -240,7 +243,7 @@ type Trivial a = FromNat (Count a) ~ a
240-- class.
243-- class.
241instance (Num e) => Category (Matrix e) where
244instance (Num e) => Category (Matrix e) where
242 type Object (Matrix e) a = (FL a a, Countable a)
245 type Object (Matrix e) a = (FL a a, Countable a)
243− id = iden
246+ id = iden
244 (.) = comp
247 (.) = comp
245
248
246instance NFData e => NFData (Matrix e cols rows) where
249instance NFData e => NFData (Matrix e cols rows) where
@@ -256,7 +259,6 @@ instance Eq e => Eq (Matrix e cols rows) where
256 x@(Join _ _) == y@(Fork _ _) = abideJF x == y
259 x@(Join _ _) == y@(Fork _ _) = abideJF x == y
257
260
258instance Num e => Num (Matrix e cols rows) where
261instance Num e => Num (Matrix e cols rows) where
259−
260 a + b = zipWithM (+) a b
262 a + b = zipWithM (+) a b
261
263
262 a - b = zipWithM (-) a b
264 a - b = zipWithM (-) a b
@@ -315,31 +317,34 @@ class FromLists cols rows where
315 -- error if the dimensions do not match.
317 -- error if the dimensions do not match.
316 fromLists :: [[e]] -> Matrix e cols rows
318 fromLists :: [[e]] -> Matrix e cols rows
317
319
318−instance {-# OVERLAPPING #-} FromLists () () where
320+instance FromLists () () where
319 fromLists [[e]] = One e
321 fromLists [[e]] = One e
320 fromLists _ = error "Wrong dimensions"
322 fromLists _ = error "Wrong dimensions"
321
323
322−instance {-# OVERLAPPING #-} (FromLists cols ()) => FromLists (Either () cols) () where
324+instance (FromLists cols ()) => FromLists (Either () cols) () where
323 fromLists [h : t] = Join (One h) (fromLists [t])
325 fromLists [h : t] = Join (One h) (fromLists [t])
324 fromLists _ = error "Wrong dimensions"
326 fromLists _ = error "Wrong dimensions"
325
327
328+instance {-# OVERLAPPABLE #-}
326−instance {-# OVERLAPPABLE #-} (FromLists a (), FromLists b (), Countable a) => FromLists (Either a b) () where
329+ (FromLists a (), FromLists b (), Countable a) => FromLists (Either a b) () where
327 fromLists [l] =
330 fromLists [l] =
328 let rowsA = fromInteger (natVal (Proxy :: Proxy (Count a)))
331 let rowsA = fromInteger (natVal (Proxy :: Proxy (Count a)))
329 in Join (fromLists [take rowsA l]) (fromLists [drop rowsA l])
332 in Join (fromLists [take rowsA l]) (fromLists [drop rowsA l])
330 fromLists _ = error "Wrong dimensions"
333 fromLists _ = error "Wrong dimensions"
331
334
332−instance {-# OVERLAPPING #-} (FromLists () rows) => FromLists () (Either () rows) where
335+instance (FromLists () rows) => FromLists () (Either () rows) where
333 fromLists ([h] : t) = Fork (One h) (fromLists t)
336 fromLists ([h] : t) = Fork (One h) (fromLists t)
334 fromLists _ = error "Wrong dimensions"
337 fromLists _ = error "Wrong dimensions"
335
338
339+instance {-# OVERLAPPABLE #-}
336−instance {-# OVERLAPPABLE #-} (FromLists () a, FromLists () b, Countable a) => FromLists () (Either a b) where
340+ (FromLists () a, FromLists () b, Countable a) => FromLists () (Either a b) where
337− fromLists l@([_] : _) =
341+ fromLists l@([_] : _) =
338 let rowsA = fromInteger (natVal (Proxy :: Proxy (Count a)))
342 let rowsA = fromInteger (natVal (Proxy :: Proxy (Count a)))
339 in Fork (fromLists (take rowsA l)) (fromLists (drop rowsA l))
343 in Fork (fromLists (take rowsA l)) (fromLists (drop rowsA l))
340 fromLists _ = error "Wrong dimensions"
344 fromLists _ = error "Wrong dimensions"
341
345
342−instance {-# OVERLAPPABLE #-} (FromLists (Either a b) c, FromLists (Either a b) d, Countable c) => FromLists (Either a b) (Either c d) where
346+instance (FromLists (Either a b) c, FromLists (Either a b) d, Countable c)
347+ => FromLists (Either a b) (Either c d) where
343 fromLists l@(h : t) =
348 fromLists l@(h : t) =
344 let lh = length h
349 let lh = length h
345 rowsC = fromInteger (natVal (Proxy :: Proxy (Count c)))
350 rowsC = fromInteger (natVal (Proxy :: Proxy (Count c)))
@@ -366,16 +371,15 @@ matrixBuilder' f =
366matrixBuilder ::
371matrixBuilder ::
367 forall e a b.
372 forall e a b.
368 ( FLN a b,
373 ( FLN a b,
369− CountableN b,
370 Enum a,
374 Enum a,
371 Enum b,
375 Enum b,
372 Bounded a,
376 Bounded a,
373 Bounded b,
377 Bounded b,
374 Eq a,
378 Eq a,
375− CountableDimsN a b
379+ Countable b
376 ) => ((a, b) -> e) -> Matrix e (Normalize a) (Normalize b)
380 ) => ((a, b) -> e) -> Matrix e (Normalize a) (Normalize b)
377matrixBuilder f =
381matrixBuilder f =
378− let r = fromInteger $ natVal (Proxy :: Proxy (Count (Normalize b)))
382+ let r = fromInteger $ natVal (Proxy :: Proxy (Count b))
379 positions = [(a, b) | a <- [minBound .. maxBound], b <- [minBound .. maxBound]]
383 positions = [(a, b) | a <- [minBound .. maxBound], b <- [minBound .. maxBound]]
380 in fromLists . map (map f) . transpose . buildList r $ positions
384 in fromLists . map (map f) . transpose . buildList r $ positions
381 where
385 where
@@ -431,24 +435,7 @@ fromF ::
431 ) =>
435 ) =>
432 (a -> b) ->
436 (a -> b) ->
433 Matrix e (Normalize a) (Normalize b)
437 Matrix e (Normalize a) (Normalize b)
434−fromF f =
438+fromF = fromF'
435− let minA = minBound @a
436− maxA = maxBound @a
437− minB = minBound @b
438− maxB = maxBound @b
439− ccols = fromInteger $ natVal (Proxy :: Proxy (Count (Normalize a)))
440− rrows = fromInteger $ natVal (Proxy :: Proxy (Count (Normalize b)))
441− elementsA = take ccols [minA .. maxA]
442− elementsB = take rrows [minB .. maxB]
443− combinations = (,) <$> elementsA <*> elementsB
444− combAp = map snd . sort . map (\(a, b) -> if f a == b
445− then ((fromEnum a, fromEnum b), 1)
446− else ((fromEnum a, fromEnum b), 0)) $ combinations
447− mList = buildList combAp rrows
448− in tr $ fromLists mList
449− where
450− buildList [] _ = []
451− buildList l r = take r l : buildList (drop r l) r
452
439
453-- Conversion
440-- Conversion
454
441
@@ -510,7 +497,7 @@ comp (Join a b) (Fork c d) = comp a c + comp b d -- Divide-and-conquer l
510comp (Fork a b) c = Fork (comp a c) (comp b c) -- Fork fusion law
497comp (Fork a b) c = Fork (comp a c) (comp b c) -- Fork fusion law
511comp c (Join a b) = Join (comp c a) (comp c b) -- Join fusion law
498comp c (Join a b) = Join (comp c a) (comp c b) -- Join fusion law
512{-# NOINLINE comp #-}
499{-# NOINLINE comp #-}
513−{-# RULES
500+{-# RULES
514 "comp/iden1" forall m. comp m iden = m ;
501 "comp/iden1" forall m. comp m iden = m ;
515 "comp/iden2" forall m. comp iden m = m
502 "comp/iden2" forall m. comp iden m = m
516#-}
503#-}
@@ -557,24 +544,38 @@ i2 = tr p2
557
544
558-- | Obtain the number of rows.
545-- | Obtain the number of rows.
559--
546--
560−-- NOTE: The 'KnownNat' constaint is needed in order to obtain the
547+-- NOTE: The 'KnownNat' constraint is needed in order to obtain the
561−-- dimensions in constant time.
548+-- dimensions in constant time. For a version that doesn't require the
562−--
549+-- constraint see 'rows''.
563−-- TODO: A 'rows' function that does not need the 'KnownNat' constraint in
564−-- exchange for performance.
565rows :: forall e cols rows. (Countable rows) => Matrix e cols rows -> Int
550rows :: forall e cols rows. (Countable rows) => Matrix e cols rows -> Int
566rows _ = fromInteger $ natVal (Proxy :: Proxy (Count rows))
551rows _ = fromInteger $ natVal (Proxy :: Proxy (Count rows))
567
552
553+-- | Obtain the number of rows in an inefficient manner, but without any
554+-- constraints.
555+--
556+-- For a more efficient version see 'rows'.
557+rows' :: Matrix e cols rows -> Int
558+rows' (One _) = 1
559+rows' (Join lhs _) = rows' lhs
560+rows' (Fork top bottom) = rows' top + rows' bottom
561+
568-- | Obtain the number of columns.
562-- | Obtain the number of columns.
569−--
570−-- NOTE: The 'KnownNat' constaint is needed in order to obtain the
571−-- dimensions in constant time.
572--
563--
573−-- TODO: A 'columns' function that does not need the 'KnownNat' constraint in
564+-- NOTE: The 'KnownNat' constraint is needed in order to obtain the
574−-- exchange for performance.
565+-- dimensions in constant time. For a version that doesn't require the
566+-- constraint see 'columns''.
575columns :: forall e cols rows. (Countable cols) => Matrix e cols rows -> Int
567columns :: forall e cols rows. (Countable cols) => Matrix e cols rows -> Int
576columns _ = fromInteger $ natVal (Proxy :: Proxy (Count cols))
568columns _ = fromInteger $ natVal (Proxy :: Proxy (Count cols))
577
569
570+-- | Obtain the number of columns in an inefficient manner, but without any
571+-- constraints.
572+--
573+-- For a more efficient version see 'columns'.
574+columns' :: Matrix e cols rows -> Int
575+columns' (One _) = 1
576+columns' (Join lhs rhs) = columns' lhs + columns' rhs
577+columns' (Fork top _) = columns' top
578+
578-- Coproduct Bifunctor
579-- Coproduct Bifunctor
579
580
580infixl 5 -|-
581infixl 5 -|-
@@ -629,7 +630,7 @@ sndM = matrixBuilder' f
629-- | Khatri Rao Matrix product also known as matrix pairing.
630-- | Khatri Rao Matrix product also known as matrix pairing.
630--
631--
631-- NOTE: That this is not a true categorical product, see for instance:
632-- NOTE: That this is not a true categorical product, see for instance:
632−--
633+--
633-- @
634-- @
634-- | fstM . kr a b == a
635-- | fstM . kr a b == a
635-- kr a b ==> |
636-- kr a b ==> |
@@ -665,7 +666,7 @@ infixl 4 ><
665 FL (Normalize (m, n)) n,
666 FL (Normalize (m, n)) n,
666 FL (Normalize (p, q)) p,
667 FL (Normalize (p, q)) p,
667 FL (Normalize (p, q)) q
668 FL (Normalize (p, q)) q
668− )
669+ )
669 => Matrix e m p -> Matrix e n q -> Matrix e (Normalize (m, n)) (Normalize (p, q))
670 => Matrix e m p -> Matrix e n q -> Matrix e (Normalize (m, n)) (Normalize (p, q))
670(><) a b =
671(><) a b =
671 let fstM' = fstM @e @m @n
672 let fstM' = fstM @e @m @n
@@ -930,24 +931,7 @@ fromFRel' ::
930 ) =>
931 ) =>
931 (a -> b) ->
932 (a -> b) ->
932 Relation cols rows
933 Relation cols rows
933−fromFRel' f =
934+fromFRel' = fromF'
934− let minA = minBound @a
935− maxA = maxBound @a
936− minB = minBound @b
937− maxB = maxBound @b
938− ccols = fromInteger $ natVal (Proxy :: Proxy (Count cols))
939− rrows = fromInteger $ natVal (Proxy :: Proxy (Count rows))
940− elementsA = take ccols [minA .. maxA]
941− elementsB = take rrows [minB .. maxB]
942− combinations = (,) <$> elementsA <*> elementsB
943− combAp = map snd . sort . map (\(a, b) -> if f a == b
944− then ((fromEnum a, fromEnum b), nat 1)
945− else ((fromEnum a, fromEnum b), nat 0)) $ combinations
946− mList = buildList combAp rrows
947− in tr $ fromLists mList
948− where
949− buildList [] _ = []
950− buildList l r = take r l : buildList (drop r l) r
951
935
952-- | Lifts functions to relations with dimensions matching @a@ and @b@
936-- | Lifts functions to relations with dimensions matching @a@ and @b@
953-- cardinality's.
937-- cardinality's.
@@ -955,28 +939,11 @@ fromFRel ::
955 forall a b.
939 forall a b.
956 ( Liftable Boolean a b,
940 ( Liftable Boolean a b,
957 CountableDimsN a b,
941 CountableDimsN a b,
958− FL (Normalize b) (Normalize a)
942+ FLN b a
959 ) =>
943 ) =>
960 (a -> b) ->
944 (a -> b) ->
961 Relation (Normalize a) (Normalize b)
945 Relation (Normalize a) (Normalize b)
962−fromFRel f =
946+fromFRel = fromFRel'
963− let minA = minBound @a
964− maxA = maxBound @a
965− minB = minBound @b
966− maxB = maxBound @b
967− ccols = fromInteger $ natVal (Proxy :: Proxy (Count (Normalize a)))
968− rrows = fromInteger $ natVal (Proxy :: Proxy (Count (Normalize b)))
969− elementsA = take ccols [minA .. maxA]
970− elementsB = take rrows [minB .. maxB]
971− combinations = (,) <$> elementsA <*> elementsB
972− combAp = map snd . sort . map (\(a, b) -> if f a == b
973− then ((fromEnum a, fromEnum b), nat 1)
974− else ((fromEnum a, fromEnum b), nat 0)) $ combinations
975− mList = buildList combAp rrows
976− in tr $ fromLists mList
977− where
978− buildList [] _ = []
979− buildList l r = take r l : buildList (drop r l) r
980
947
981-- | Lifts a relation function to a Boolean Matrix
948-- | Lifts a relation function to a Boolean Matrix
982toRel ::
949toRel ::
@@ -986,17 +953,17 @@ toRel ::
986 Enum a,
953 Enum a,
987 Enum b,
954 Enum b,
988 Eq b,
955 Eq b,
989− CountableDimsN a b,
956+ CountableDims a b,
990 FLN b a
957 FLN b a
991− )
958+ )
992 => (a -> b -> Bool) -> Relation (Normalize a) (Normalize b)
959 => (a -> b -> Bool) -> Relation (Normalize a) (Normalize b)
993toRel f =
960toRel f =
994 let minA = minBound @a
961 let minA = minBound @a
995 maxA = maxBound @a
962 maxA = maxBound @a
996 minB = minBound @b
963 minB = minBound @b
997 maxB = maxBound @b
964 maxB = maxBound @b
998− ccols = fromInteger $ natVal (Proxy :: Proxy (Count (Normalize a)))
965+ ccols = fromInteger $ natVal (Proxy :: Proxy (Count a))
999− rrows = fromInteger $ natVal (Proxy :: Proxy (Count (Normalize b)))
966+ rrows = fromInteger $ natVal (Proxy :: Proxy (Count b))
1000 elementsA = take ccols [minA .. maxA]
967 elementsA = take ccols [minA .. maxA]
1001 elementsB = take rrows [minB .. maxB]
968 elementsB = take rrows [minB .. maxB]
1002 combinations = (,) <$> elementsA <*> elementsB
969 combinations = (,) <$> elementsA <*> elementsB
src/LAoP/Matrix/Type.hs+42−30
@@ -104,8 +104,8 @@ module LAoP.Matrix.Type
104 multM,
104 multM,
105
105
106 -- * Selective equivalent instance function
106 -- * Selective equivalent instance function
107− selectM,
107+ selectM,
108−
108+
109 -- * Monad equivalent instance function
109 -- * Monad equivalent instance function
110 returnM,
110 returnM,
111 bindM,
111 bindM,
@@ -113,7 +113,9 @@ module LAoP.Matrix.Type
113 -- * Misc
113 -- * Misc
114 -- ** Get dimensions
114 -- ** Get dimensions
115 columns,
115 columns,
116+ columns',
116 rows,
117 rows,
118+ rows',
117
119
118 -- ** Matrix Transposition
120 -- ** Matrix Transposition
119 tr,
121 tr,
@@ -265,7 +267,7 @@ infixl 2 ===
265-- Functor hierarchy
267-- Functor hierarchy
266
268
267-- | Functor instance equivalent function
269-- | Functor instance equivalent function
268−fmapM ::
270+fmapM ::
269 ( Liftable e a b,
271 ( Liftable e a b,
270 CountableDimsN a b,
272 CountableDimsN a b,
271 FLN b a
273 FLN b a
@@ -279,7 +281,7 @@ unitM :: (Num e) => Matrix e () ()
279unitM = one 1
281unitM = one 1
280
282
281-- | Applicative instance equivalent 'unit' function,
283-- | Applicative instance equivalent 'unit' function,
282−multM ::
284+multM ::
283 ( CountableDimsN a b,
285 ( CountableDimsN a b,
284 CountableN (a, b),
286 CountableN (a, b),
285 Num e,
287 Num e,
@@ -290,8 +292,8 @@ multM ::
290multM = kr
292multM = kr
291
293
292-- | Monad instance equivalent 'return' function,
294-- | Monad instance equivalent 'return' function,
293−returnM ::
295+returnM ::
294− forall e a .
296+ forall e a .
295 ( Num e,
297 ( Num e,
296 Enum e,
298 Enum e,
297 Enum a,
299 Enum a,
@@ -331,7 +333,7 @@ matrixBuilder ::
331 Bounded a,
333 Bounded a,
332 Bounded b,
334 Bounded b,
333 Eq a,
335 Eq a,
334− CountableDimsN a b
336+ Countable b
335 ) => ((a, b) -> e) -> Matrix e a b
337 ) => ((a, b) -> e) -> Matrix e a b
336matrixBuilder f = M (I.matrixBuilder f)
338matrixBuilder f = M (I.matrixBuilder f)
337
339
@@ -368,7 +370,7 @@ fromF = M . I.fromF
368-- | Lifts relation functions to Boolean Matrix
370-- | Lifts relation functions to Boolean Matrix
369toRel ::
371toRel ::
370 ( Liftable (Natural 0 1) a b,
372 ( Liftable (Natural 0 1) a b,
371− CountableDimsN a b,
373+ CountableDims a b,
372 FLN b a
374 FLN b a
373 ) => (a -> b -> Bool) -> Matrix (Natural 0 1) a b
375 ) => (a -> b -> Bool) -> Matrix (Natural 0 1) a b
374toRel = M . I.toRel
376toRel = M . I.toRel
@@ -387,7 +389,7 @@ toList (M m) = I.toList m
387
389
388-- | The zero matrix. A matrix wholly filled with zeros.
390-- | The zero matrix. A matrix wholly filled with zeros.
389zeros ::
391zeros ::
390− (Num e, FLN cols rows, CountableDimsN cols rows)
392+ (Num e, FLN cols rows, CountableDimsN cols rows)
391 => Matrix e cols rows
393 => Matrix e cols rows
392zeros = M I.zeros
394zeros = M I.zeros
393
395
@@ -397,7 +399,7 @@ zeros = M I.zeros
397--
399--
398-- Also known as T (Top) matrix.
400-- Also known as T (Top) matrix.
399ones ::
401ones ::
400− (Num e, FLN cols rows, CountableDimsN cols rows)
402+ (Num e, FLN cols rows, CountableDimsN cols rows)
401 => Matrix e cols rows
403 => Matrix e cols rows
402ones = M I.ones
404ones = M I.ones
403
405
@@ -406,7 +408,7 @@ ones = M I.ones
406-- | The constant matrix constructor. A matrix wholly filled with a given
408-- | The constant matrix constructor. A matrix wholly filled with a given
407-- value.
409-- value.
408constant ::
410constant ::
409− (Num e, FLN cols rows, CountableDimsN cols rows)
411+ (Num e, FLN cols rows, CountableDimsN cols rows)
410 => e -> Matrix e cols rows
412 => e -> Matrix e cols rows
411constant = M . I.constant
413constant = M . I.constant
412
414
@@ -420,7 +422,7 @@ bang ::
420bang = M I.bang
422bang = M I.bang
421
423
422-- | Point constant relation
424-- | Point constant relation
423−point ::
425+point ::
424 ( Bounded a,
426 ( Bounded a,
425 Enum a,
427 Enum a,
426 Eq a,
428 Eq a,
@@ -449,7 +451,7 @@ iden = M I.iden
449comp :: (Num e) => Matrix e cr rows -> Matrix e cols cr -> Matrix e cols rows
451comp :: (Num e) => Matrix e cr rows -> Matrix e cols cr -> Matrix e cols rows
450comp (M a) (M b) = M (I.comp a b)
452comp (M a) (M b) = M (I.comp a b)
451{-# NOINLINE comp #-}
453{-# NOINLINE comp #-}
452−{-# RULES
454+{-# RULES
453 "comp/iden1" forall m. comp m iden = m ;
455 "comp/iden1" forall m. comp m iden = m ;
454 "comp/iden2" forall m. comp iden m = m
456 "comp/iden2" forall m. comp iden m = m
455#-}
457#-}
@@ -514,24 +516,34 @@ i2 = tr p2
514
516
515-- | Obtain the number of rows.
517-- | Obtain the number of rows.
516--
518--
517−-- NOTE: The 'KnownNat' constaint is needed in order to obtain the
519+-- NOTE: The 'KnownNat' constraint is needed in order to obtain the
518−-- dimensions in constant time.
520+-- dimensions in constant time. For a version that doesn't require the
519−--
521+-- constraint see 'rows''.
520−-- TODO: A 'rows' function that does not need the 'KnownNat' constraint in
521−-- exchange for performance.
522rows :: (CountableN rows) => Matrix e cols rows -> Int
522rows :: (CountableN rows) => Matrix e cols rows -> Int
523rows (M m) = I.rows m
523rows (M m) = I.rows m
524
524
525+-- | Obtain the number of rows in an inefficient manner, but without any
526+-- constraints.
527+--
528+-- For a more efficient version see 'rows'.
529+rows' :: Matrix e cols rows -> Int
530+rows' (M m) = I.rows' m
531+
525-- | Obtain the number of columns.
532-- | Obtain the number of columns.
526−--
527−-- NOTE: The 'KnownNat' constaint is needed in order to obtain the
528−-- dimensions in constant time.
529--
533--
530−-- TODO: A 'columns' function that does not need the 'KnownNat' constraint in
534+-- NOTE: The 'KnownNat' constraint is needed in order to obtain the
531−-- exchange for performance.
535+-- dimensions in constant time. For a version that doesn't require the
536+-- constraint see 'columns''.
532columns :: (CountableN cols) => Matrix e cols rows -> Int
537columns :: (CountableN cols) => Matrix e cols rows -> Int
533columns (M m) = I.columns m
538columns (M m) = I.columns m
534
539
540+-- | Obtain the number of columns in an inefficient manner, but without any
541+-- constraints.
542+--
543+-- For a more efficient version see 'columns'.
544+columns' :: Matrix e cols rows -> Int
545+columns' (M m) = I.columns' m
546+
535-- Coproduct Bifunctor
547-- Coproduct Bifunctor
536
548
537infixl 5 -|-
549infixl 5 -|-
@@ -553,7 +565,7 @@ infixl 5 -|-
553-- Khatri Rao Product and projections
565-- Khatri Rao Product and projections
554
566
555-- | Khatri Rao product first component projection matrix.
567-- | Khatri Rao product first component projection matrix.
556−fstM ::
568+fstM ::
557 forall e m k .
569 forall e m k .
558 ( Num e,
570 ( Num e,
559 CountableDimsN m k,
571 CountableDimsN m k,
@@ -564,7 +576,7 @@ fstM ::
564fstM = M (I.fstM @e @(I.Normalize m) @(I.Normalize k))
576fstM = M (I.fstM @e @(I.Normalize m) @(I.Normalize k))
565
577
566-- | Khatri Rao product second component projection matrix.
578-- | Khatri Rao product second component projection matrix.
567−sndM ::
579+sndM ::
568 forall e m k.
580 forall e m k.
569 ( Num e,
581 ( Num e,
570 CountableDimsN k m,
582 CountableDimsN k m,
@@ -577,9 +589,9 @@ sndM = M (I.sndM @e @(I.Normalize m) @(I.Normalize k))
577-- | Khatri Rao Matrix product also known as matrix pairing.
589-- | Khatri Rao Matrix product also known as matrix pairing.
578--
590--
579-- NOTE: That this is not a true categorical product, see for instance:
591-- NOTE: That this is not a true categorical product, see for instance:
580−--
592+--
581-- @
593-- @
582−-- | fstM . kr a b == a
594+-- | fstM . kr a b == a
583-- kr a b ==> |
595-- kr a b ==> |
584-- | sndM . kr a b == b
596-- | sndM . kr a b == b
585-- @
597-- @
@@ -625,7 +637,7 @@ infixl 4 ><
625-- Matrix abide Join Fork
637-- Matrix abide Join Fork
626
638
627-- | Matrix "abiding" followin the 'Join'-'Fork' abide law.
639-- | Matrix "abiding" followin the 'Join'-'Fork' abide law.
628−--
640+--
629-- Law:
641-- Law:
630--
642--
631-- @
643-- @
@@ -637,7 +649,7 @@ abideJF (M m) = M (I.abideJF m)
637-- Matrix abide Fork Join
649-- Matrix abide Fork Join
638
650
639-- | Matrix "abiding" followin the 'Fork'-'Join' abide law.
651-- | Matrix "abiding" followin the 'Fork'-'Join' abide law.
640−--
652+--
641-- Law:
653-- Law:
642--
654--
643-- @
655-- @
@@ -656,7 +668,7 @@ tr (M m) = M (I.tr m)
656
668
657-- | Selective functors 'select' operator equivalent inspired by the
669-- | Selective functors 'select' operator equivalent inspired by the
658-- ArrowMonad solution presented in the paper.
670-- ArrowMonad solution presented in the paper.
659−selectM ::
671+selectM ::
660 ( Num e,
672 ( Num e,
661 FLN b b,
673 FLN b b,
662 CountableN b
674 CountableN b
src/LAoP/Relation/Internal.hs+12−9
@@ -283,7 +283,7 @@ relationBuilder ::
283 Bounded a,
283 Bounded a,
284 Bounded b,
284 Bounded b,
285 Eq a,
285 Eq a,
286− CountableDimsN a b
286+ CountableDims a b
287 ) => ((a, b) -> Boolean) -> Relation a b
287 ) => ((a, b) -> Boolean) -> Relation a b
288relationBuilder = R . I.matrixBuilder
288relationBuilder = R . I.matrixBuilder
289
289
@@ -301,7 +301,7 @@ fromF' f = R (I.fromFRel' f)
301
301
302-- | Lifts functions to matrices with dimensions matching @a@ and @b@
302-- | Lifts functions to matrices with dimensions matching @a@ and @b@
303-- cardinality's.
303-- cardinality's.
304−fromF ::
304+fromF ::
305 ( Liftable a b,
305 ( Liftable a b,
306 CountableDimsN a b,
306 CountableDimsN a b,
307 FLN b a
307 FLN b a
@@ -312,7 +312,7 @@ fromF f = R (I.fromFRel f)
312-- | Lifts relation functions to 'Relation'
312-- | Lifts relation functions to 'Relation'
313toRel ::
313toRel ::
314 ( Liftable a b,
314 ( Liftable a b,
315− CountableDimsN a b,
315+ CountableDims a b,
316 FLN b a
316 FLN b a
317 )
317 )
318 => (a -> b -> Bool) -> Relation a b
318 => (a -> b -> Bool) -> Relation a b
@@ -348,7 +348,7 @@ toBool r = case toList r of
348-- | Power transpose.
348-- | Power transpose.
349--
349--
350-- Maps a relation to a set valued function.
350-- Maps a relation to a set valued function.
351−pt ::
351+pt ::
352 ( Liftable a b,
352 ( Liftable a b,
353 Eq a,
353 Eq a,
354 CountableDimsN a b,
354 CountableDimsN a b,
@@ -365,7 +365,7 @@ belongs ::
365 ( Bounded a,
365 ( Bounded a,
366 Enum a,
366 Enum a,
367 Eq a,
367 Eq a,
368− CountableDimsN (List a) a,
368+ CountableDims (List a) a,
369 FLN a (List a)
369 FLN a (List a)
370 )
370 )
371 => Relation (List a) a
371 => Relation (List a) a
@@ -413,7 +413,7 @@ bang ::
413bang = ones
413bang = ones
414
414
415-- | Point constant relation
415-- | Point constant relation
416−point ::
416+point ::
417 ( Bounded a,
417 ( Bounded a,
418 Enum a,
418 Enum a,
419 Eq a,
419 Eq a,
@@ -927,6 +927,7 @@ untrans s = fstR . conv (splitR (conv s) sndR)
927predR ::
927predR ::
928 ( Bounded a,
928 ( Bounded a,
929 Enum a,
929 Enum a,
930+ Countable a,
930 CountableN a,
931 CountableN a,
931 FLN a a,
932 FLN a a,
932 FLN Bool a
933 FLN Bool a
@@ -954,23 +955,25 @@ equalizer f g = id `intersection` divisionF f g
954-- @
955-- @
955-- 'guard' p = 'i2' ``overriddenBy`` 'i1' `.` 'predR' p
956-- 'guard' p = 'i2' ``overriddenBy`` 'i1' `.` 'predR' p
956-- @
957-- @
957−guard ::
958+guard ::
958 ( Bounded b,
959 ( Bounded b,
959 Enum b,
960 Enum b,
960 CountableN b,
961 CountableN b,
962+ Countable b,
961 FLN b b,
963 FLN b b,
962 FLN Bool b
964 FLN Bool b
963 ) => Relation b Bool -> Relation b (Either b b)
965 ) => Relation b Bool -> Relation b (Either b b)
964guard p = conv (eitherR (predR p) (predR (negate p)))
966guard p = conv (eitherR (predR p) (predR (negate p)))
965
967
966-- | Relational McCarthy's conditional.
968-- | Relational McCarthy's conditional.
967−cond ::
969+cond ::
968 ( Bounded b,
970 ( Bounded b,
969 Enum b,
971 Enum b,
972+ Countable b,
970 CountableN b,
973 CountableN b,
971 FLN b b,
974 FLN b b,
972 FLN Bool b
975 FLN Bool b
973− )
976+ )
974 => Relation b Bool -> Relation b c -> Relation b c -> Relation b c
977 => Relation b Bool -> Relation b c -> Relation b c -> Relation b c
975cond p r s = eitherR r s . guard p
978cond p r s = eitherR r s . guard p
976
979
stack-8.8.3.yamlnew file+1
@@ -0,0 +1 @@
1+resolver: lts-15.5
stack.yaml+1−66
@@ -1,66 +1 @@
1−# This file was automatically generated by 'stack init'
2−#
3−# Some commonly used options have been documented as comments in this file.
4−# For advanced use and comprehensive documentation of the format, please see:
5−# https://docs.haskellstack.org/en/stable/yaml_configuration/
6−
7−# Resolver to choose a 'specific' stackage snapshot or a compiler version.
8−# A snapshot resolver dictates the compiler version and the set of packages
9−# to be used for project dependencies. For example:
10−#
11−# resolver: lts-3.5
12−# resolver: nightly-2015-09-21
13−# resolver: ghc-7.10.2
14−#
15−# The location of a snapshot can be provided as a file or url. Stack assumes
16−# a snapshot provided as a file might change, whereas a url resource does not.
17−#
18−# resolver: ./custom-snapshot.yaml
19−# resolver: https://example.com/snapshots/2018-01-01.yaml
20−resolver: lts-14.18
1+resolver: lts-14.3
21−
22−# User packages to be built.
23−# Various formats can be used as shown in the example below.
24−#
25−# packages:
26−# - some-directory
27−# - https://example.com/foo/bar/baz-0.0.2.tar.gz
28−# subdirs:
29−# - auto-update
30−# - wai
31−packages:
32−- .
33−# Dependency packages to be pulled from upstream that are not in the resolver.
34−# These entries can reference officially published versions as well as
35−# forks / in-progress versions pinned to a git hash. For example:
36−#
37−# extra-deps:
38−# - acme-missiles-0.3
39−# - git: https://github.com/commercialhaskell/stack.git
40−# commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a
41−#
42−# extra-deps: []
43−
44−# Override default flag values for local packages and extra-deps
45−# flags: {}
46−
47−# Extra package databases containing global packages
48−# extra-package-dbs: []
49−
50−# Control whether we use the GHC we find on the path
51−# system-ghc: true
52−#
53−# Require a specific version of stack, using version ranges
54−# require-stack-version: -any # Default
55−# require-stack-version: ">=2.1"
56−#
57−# Override the architecture used by stack, especially useful on Windows
58−# arch: i386
59−# arch: x86_64
60−#
61−# Extra directories used by stack for building
62−# extra-include-dirs: [/path/to/dir]
63−# extra-lib-dirs: [/path/to/dir]
64−#
65−# Allow a newer minor version of GHC than the snapshot specifies
66−# compiler-check: newer-minor
stack.yaml.lock+4−4
@@ -6,7 +6,7 @@
6packages: []
6packages: []
7snapshots:
7snapshots:
8- completed:
8- completed:
9− size: 524789
9+ size: 523878
10− url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/14/18.yaml
10+ url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/14/3.yaml
11− sha256: 646be71223e08234131c6989912e6011e01b9767bc447b6d466a35e14360bdf2
11+ sha256: 470c46c27746a48c7c50f829efc0cf00112787a7804ee4ac7a27754658f6d92c
12− original: lts-14.18
12+ original: lts-14.3
app/Quantum.hs → test/Examples/Quantum.hsrenamed+2−2
@@ -1,5 +1,5 @@
1{-# LANGUAGE StandaloneDeriving #-}
1{-# LANGUAGE StandaloneDeriving #-}
2−module Quantum where
2+module Examples.Quantum where
3
3
4import LAoP.Utils
4import LAoP.Utils
5import LAoP.Matrix.Type
5import LAoP.Matrix.Type
@@ -21,7 +21,7 @@ cnot = kr fstM (fromF xor)
21ccnot :: (Num e, Ord e) => Matrix e ((Bool, Bool), Bool) ((Bool, Bool), Bool)
21ccnot :: (Num e, Ord e) => Matrix e ((Bool, Bool), Bool) ((Bool, Bool), Bool)
22ccnot = kr fstM (fromF f)
22ccnot = kr fstM (fromF f)
23 where
23 where
24− f = xor . (tp (uncurry (&&)) id)
24+ f = xor . tp (uncurry (&&)) id
25 tp f g (a,b) = (f a, g b)
25 tp f g (a,b) = (f a, g b)
26
26
27had :: Matrix (Complex Double) Bool Bool
27had :: Matrix (Complex Double) Bool Bool
app/Examples.hs → test/Examples/Readme.hsrenamed+1−2
@@ -1,11 +1,10 @@
1{-# LANGUAGE GADTs #-}
1{-# LANGUAGE GADTs #-}
2{-# LANGUAGE DeriveGeneric #-}
2{-# LANGUAGE DeriveGeneric #-}
3{-# LANGUAGE FlexibleContexts #-}
3{-# LANGUAGE FlexibleContexts #-}
4−{-# LANGUAGE TypeOperators #-}
5{-# LANGUAGE TypeApplications #-}
4{-# LANGUAGE TypeApplications #-}
6{-# LANGUAGE DataKinds #-}
5{-# LANGUAGE DataKinds #-}
7
6
8−module Examples
7+module Examples.Readme
9 ( exec
8 ( exec
10 )
9 )
11 where
10 where
app/Spreadsheets.hs → test/Examples/Spreadsheets.hsrenamed+1−2
@@ -1,7 +1,6 @@
1{-# LANGUAGE DeriveGeneric #-}
1{-# LANGUAGE DeriveGeneric #-}
2
2
3−module Spreadsheets
3+module Examples.Spreadsheets
4− where
5
4
6import LAoP.Utils
5import LAoP.Utils
7import LAoP.Matrix.Type
6import LAoP.Matrix.Type
test/Spec.hs+7−1
@@ -1,2 +1,8 @@
1+module Main (main) where
2+
3+import qualified Examples.Readme as RD
4+
1main :: IO ()
5main :: IO ()
2−main = putStrLn "Test suite not yet implemented"
6+main = do
7+ putStrLn ("Testing if README works" :: String)
8+ RD.exec