on 68cbe58 help sign in
8 files changed+86−42
since splitsnapshots
unifiedsplit
.gitignore−1 .travis.yml+4−1 CHANGELOG.md−4 README.md+1−1 laop.cabal+4−5 src/LAoP/Matrix/Internal.hs+66−16 src/LAoP/Matrix/Type.hs+2−2 src/LAoP/Relation/Internal.hs+9−12
.gitignore−1
@@ -52,4 +52,3 @@ TAGS
5252
5353# other
5454.DS_Store
55−hackage.sh
.travis.yml+4−1
@@ -25,6 +25,9 @@ matrix:
2525
2626
2727install:
28+ # HLint check
29+ - curl -sSL https://raw.github.com/ndmitchell/neil/master/misc/travis.sh | sh -s -- hlint .
30+
2831 - |
2932 if [ -z "$STACK_YAML" ]; then
3033 cabal v2-update
@@ -32,7 +35,7 @@ install:
3235 else
3336 curl -sSL https://get.haskellstack.org/ | sh
3437 stack --version
35− stack build --system-ghc --test --bench --no-run-tests --no-run-benchmarks
38+ stack build --system-ghc --test --bench --no-run-tests --no-run-benchmarks --ghc-options=-Werror
3639 fi
3740
3841script:
CHANGELOG.md−4
@@ -3,10 +3,6 @@
33`laop` uses [PVP Versioning][1].
44The changelog is available [on GitHub][2].
55
6−## 0.1.1.1
7−
8−* Bump base version to work with cabal
9−
106## 0.1.1.0
117
128* Package is more organized and now has tests and benchmarks separated
README.md+1−1
@@ -22,7 +22,7 @@ A Functional Pearl has been written and can be regarded as the [reference docume
2222
2323## Features
2424
25−This library offers 3 main matrix programming modules:
25+This library offers 4 main matrix programming modules:
2626
2727- One in which matrices are typed with type level natural numbers;
2828- One in which matrices are typed with arbitrary generic data types;
laop.cabal+4−5
@@ -1,9 +1,8 @@
11cabal-version: 2.4
22name: 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
3+version: 0.1.1.0
4+synopsis: See README for more info
5+description: See README for more info
76homepage: https://github.com/bolt12/laop
87bug-reports: https://github.com/bolt12/laop/issues
98license: MIT
@@ -23,7 +22,7 @@ source-repository head
2322 location: https://github.com/bolt12/laop.git
2423
2524common common-options
26− build-depends: base >= 4.12.0.0 && < 5,
25+ build-depends: base >= 4.12.0.0 && < 4.14,
2726 deepseq
2827
2928 ghc-options: -Wall
src/LAoP/Matrix/Internal.hs+66−16
@@ -243,7 +243,7 @@ type Trivial a = FromNat (Count a) ~ a
243243-- class.
244244instance (Num e) => Category (Matrix e) where
245245 type Object (Matrix e) a = (FL a a, Countable a)
246− id = iden
246+ id = iden
247247 (.) = comp
248248
249249instance NFData e => NFData (Matrix e cols rows) where
@@ -259,6 +259,7 @@ instance Eq e => Eq (Matrix e cols rows) where
259259 x@(Join _ _) == y@(Fork _ _) = abideJF x == y
260260
261261instance Num e => Num (Matrix e cols rows) where
262+
262263 a + b = zipWithM (+) a b
263264
264265 a - b = zipWithM (-) a b
@@ -325,8 +326,7 @@ instance (FromLists cols ()) => FromLists (Either () cols) () where
325326 fromLists [h : t] = Join (One h) (fromLists [t])
326327 fromLists _ = error "Wrong dimensions"
327328
328−instance {-# OVERLAPPABLE #-}
329− (FromLists a (), FromLists b (), Countable a) => FromLists (Either a b) () where
329+instance {-# OVERLAPPABLE #-} (FromLists a (), FromLists b (), Countable a) => FromLists (Either a b) () where
330330 fromLists [l] =
331331 let rowsA = fromInteger (natVal (Proxy :: Proxy (Count a)))
332332 in Join (fromLists [take rowsA l]) (fromLists [drop rowsA l])
@@ -336,15 +336,13 @@ instance (FromLists () rows) => FromLists () (Either () rows) where
336336 fromLists ([h] : t) = Fork (One h) (fromLists t)
337337 fromLists _ = error "Wrong dimensions"
338338
339−instance {-# OVERLAPPABLE #-}
340− (FromLists () a, FromLists () b, Countable a) => FromLists () (Either a b) where
339+instance {-# OVERLAPPABLE #-} (FromLists () a, FromLists () b, Countable a) => FromLists () (Either a b) where
341340 fromLists l@([_] : _) =
342341 let rowsA = fromInteger (natVal (Proxy :: Proxy (Count a)))
343342 in Fork (fromLists (take rowsA l)) (fromLists (drop rowsA l))
344343 fromLists _ = error "Wrong dimensions"
345344
346−instance (FromLists (Either a b) c, FromLists (Either a b) d, Countable c)
347− => FromLists (Either a b) (Either c d) where
345+instance (FromLists (Either a b) c, FromLists (Either a b) d, Countable c) => FromLists (Either a b) (Either c d) where
348346 fromLists l@(h : t) =
349347 let lh = length h
350348 rowsC = fromInteger (natVal (Proxy :: Proxy (Count c)))
@@ -371,15 +369,16 @@ matrixBuilder' f =
371369matrixBuilder ::
372370 forall e a b.
373371 ( FLN a b,
372+ CountableN b,
374373 Enum a,
375374 Enum b,
376375 Bounded a,
377376 Bounded b,
378377 Eq a,
379− Countable b
378+ CountableDimsN a b
380379 ) => ((a, b) -> e) -> Matrix e (Normalize a) (Normalize b)
381380matrixBuilder f =
382− let r = fromInteger $ natVal (Proxy :: Proxy (Count b))
381+ let r = fromInteger $ natVal (Proxy :: Proxy (Count (Normalize b)))
383382 positions = [(a, b) | a <- [minBound .. maxBound], b <- [minBound .. maxBound]]
384383 in fromLists . map (map f) . transpose . buildList r $ positions
385384 where
@@ -435,7 +434,24 @@ fromF ::
435434 ) =>
436435 (a -> b) ->
437436 Matrix e (Normalize a) (Normalize b)
438−fromF = fromF'
437+fromF f =
438+ let minA = minBound @a
439+ maxA = maxBound @a
440+ minB = minBound @b
441+ maxB = maxBound @b
442+ ccols = fromInteger $ natVal (Proxy :: Proxy (Count (Normalize a)))
443+ rrows = fromInteger $ natVal (Proxy :: Proxy (Count (Normalize b)))
444+ elementsA = take ccols [minA .. maxA]
445+ elementsB = take rrows [minB .. maxB]
446+ combinations = (,) <$> elementsA <*> elementsB
447+ combAp = map snd . sort . map (\(a, b) -> if f a == b
448+ then ((fromEnum a, fromEnum b), 1)
449+ else ((fromEnum a, fromEnum b), 0)) $ combinations
450+ mList = buildList combAp rrows
451+ in tr $ fromLists mList
452+ where
453+ buildList [] _ = []
454+ buildList l r = take r l : buildList (drop r l) r
439455
440456-- Conversion
441457
@@ -931,7 +947,24 @@ fromFRel' ::
931947 ) =>
932948 (a -> b) ->
933949 Relation cols rows
934−fromFRel' = fromF'
950+fromFRel' f =
951+ let minA = minBound @a
952+ maxA = maxBound @a
953+ minB = minBound @b
954+ maxB = maxBound @b
955+ ccols = fromInteger $ natVal (Proxy :: Proxy (Count cols))
956+ rrows = fromInteger $ natVal (Proxy :: Proxy (Count rows))
957+ elementsA = take ccols [minA .. maxA]
958+ elementsB = take rrows [minB .. maxB]
959+ combinations = (,) <$> elementsA <*> elementsB
960+ combAp = map snd . sort . map (\(a, b) -> if f a == b
961+ then ((fromEnum a, fromEnum b), nat 1)
962+ else ((fromEnum a, fromEnum b), nat 0)) $ combinations
963+ mList = buildList combAp rrows
964+ in tr $ fromLists mList
965+ where
966+ buildList [] _ = []
967+ buildList l r = take r l : buildList (drop r l) r
935968
936969-- | Lifts functions to relations with dimensions matching @a@ and @b@
937970-- cardinality's.
@@ -939,11 +972,28 @@ fromFRel ::
939972 forall a b.
940973 ( Liftable Boolean a b,
941974 CountableDimsN a b,
942− FLN b a
975+ FL (Normalize b) (Normalize a)
943976 ) =>
944977 (a -> b) ->
945978 Relation (Normalize a) (Normalize b)
946−fromFRel = fromFRel'
979+fromFRel f =
980+ let minA = minBound @a
981+ maxA = maxBound @a
982+ minB = minBound @b
983+ maxB = maxBound @b
984+ ccols = fromInteger $ natVal (Proxy :: Proxy (Count (Normalize a)))
985+ rrows = fromInteger $ natVal (Proxy :: Proxy (Count (Normalize b)))
986+ elementsA = take ccols [minA .. maxA]
987+ elementsB = take rrows [minB .. maxB]
988+ combinations = (,) <$> elementsA <*> elementsB
989+ combAp = map snd . sort . map (\(a, b) -> if f a == b
990+ then ((fromEnum a, fromEnum b), nat 1)
991+ else ((fromEnum a, fromEnum b), nat 0)) $ combinations
992+ mList = buildList combAp rrows
993+ in tr $ fromLists mList
994+ where
995+ buildList [] _ = []
996+ buildList l r = take r l : buildList (drop r l) r
947997
948998-- | Lifts a relation function to a Boolean Matrix
949999toRel ::
@@ -953,7 +1003,7 @@ toRel ::
9531003 Enum a,
9541004 Enum b,
9551005 Eq b,
956− CountableDims a b,
1006+ CountableDimsN a b,
9571007 FLN b a
9581008 )
9591009 => (a -> b -> Bool) -> Relation (Normalize a) (Normalize b)
@@ -962,8 +1012,8 @@ toRel f =
9621012 maxA = maxBound @a
9631013 minB = minBound @b
9641014 maxB = maxBound @b
965− ccols = fromInteger $ natVal (Proxy :: Proxy (Count a))
966− rrows = fromInteger $ natVal (Proxy :: Proxy (Count b))
1015+ ccols = fromInteger $ natVal (Proxy :: Proxy (Count (Normalize a)))
1016+ rrows = fromInteger $ natVal (Proxy :: Proxy (Count (Normalize b)))
9671017 elementsA = take ccols [minA .. maxA]
9681018 elementsB = take rrows [minB .. maxB]
9691019 combinations = (,) <$> elementsA <*> elementsB
src/LAoP/Matrix/Type.hs+2−2
@@ -333,7 +333,7 @@ matrixBuilder ::
333333 Bounded a,
334334 Bounded b,
335335 Eq a,
336− Countable b
336+ CountableDimsN a b
337337 ) => ((a, b) -> e) -> Matrix e a b
338338matrixBuilder f = M (I.matrixBuilder f)
339339
@@ -370,7 +370,7 @@ fromF = M . I.fromF
370370-- | Lifts relation functions to Boolean Matrix
371371toRel ::
372372 ( Liftable (Natural 0 1) a b,
373− CountableDims a b,
373+ CountableDimsN a b,
374374 FLN b a
375375 ) => (a -> b -> Bool) -> Matrix (Natural 0 1) a b
376376toRel = M . I.toRel
src/LAoP/Relation/Internal.hs+9−12
@@ -283,7 +283,7 @@ relationBuilder ::
283283 Bounded a,
284284 Bounded b,
285285 Eq a,
286− CountableDims a b
286+ CountableDimsN a b
287287 ) => ((a, b) -> Boolean) -> Relation a b
288288relationBuilder = R . I.matrixBuilder
289289
@@ -301,7 +301,7 @@ fromF' f = R (I.fromFRel' f)
301301
302302-- | Lifts functions to matrices with dimensions matching @a@ and @b@
303303-- cardinality's.
304−fromF ::
304+fromF ::
305305 ( Liftable a b,
306306 CountableDimsN a b,
307307 FLN b a
@@ -312,7 +312,7 @@ fromF f = R (I.fromFRel f)
312312-- | Lifts relation functions to 'Relation'
313313toRel ::
314314 ( Liftable a b,
315− CountableDims a b,
315+ CountableDimsN a b,
316316 FLN b a
317317 )
318318 => (a -> b -> Bool) -> Relation a b
@@ -348,7 +348,7 @@ toBool r = case toList r of
348348-- | Power transpose.
349349--
350350-- Maps a relation to a set valued function.
351−pt ::
351+pt ::
352352 ( Liftable a b,
353353 Eq a,
354354 CountableDimsN a b,
@@ -365,7 +365,7 @@ belongs ::
365365 ( Bounded a,
366366 Enum a,
367367 Eq a,
368− CountableDims (List a) a,
368+ CountableDimsN (List a) a,
369369 FLN a (List a)
370370 )
371371 => Relation (List a) a
@@ -413,7 +413,7 @@ bang ::
413413bang = ones
414414
415415-- | Point constant relation
416−point ::
416+point ::
417417 ( Bounded a,
418418 Enum a,
419419 Eq a,
@@ -927,7 +927,6 @@ untrans s = fstR . conv (splitR (conv s) sndR)
927927predR ::
928928 ( Bounded a,
929929 Enum a,
930− Countable a,
931930 CountableN a,
932931 FLN a a,
933932 FLN Bool a
@@ -955,25 +954,23 @@ equalizer f g = id `intersection` divisionF f g
955954-- @
956955-- 'guard' p = 'i2' ``overriddenBy`` 'i1' `.` 'predR' p
957956-- @
958−guard ::
957+guard ::
959958 ( Bounded b,
960959 Enum b,
961960 CountableN b,
962− Countable b,
963961 FLN b b,
964962 FLN Bool b
965963 ) => Relation b Bool -> Relation b (Either b b)
966964guard p = conv (eitherR (predR p) (predR (negate p)))
967965
968966-- | Relational McCarthy's conditional.
969−cond ::
967+cond ::
970968 ( Bounded b,
971969 Enum b,
972− Countable b,
973970 CountableN b,
974971 FLN b b,
975972 FLN Bool b
976− )
973+ )
977974 => Relation b Bool -> Relation b c -> Relation b c -> Relation b c
978975cond p r s = eitherR r s . guard p
979976