on master help sign in
.gitignore+1
since splitsnapshots
unifiedsplit
@@ -52,3 +52,4 @@ TAGS
52
52
53# other
53# other
54.DS_Store
54.DS_Store
55+hackage.sh
.travis.yml+1−1
@@ -32,7 +32,7 @@ install:
32 else
32 else
33 curl -sSL https://get.haskellstack.org/ | sh
33 curl -sSL https://get.haskellstack.org/ | sh
34 stack --version
34 stack --version
35− stack build --system-ghc --test --bench --no-run-tests --no-run-benchmarks --ghc-options=-Werror
35+ stack build --system-ghc --test --bench --no-run-tests --no-run-benchmarks
36 fi
36 fi
37
37
38script:
38script:
CHANGELOG.md+4
@@ -3,6 +3,10 @@
3`laop` uses [PVP Versioning][1].
3`laop` uses [PVP Versioning][1].
4The changelog is available [on GitHub][2].
4The changelog is available [on GitHub][2].
5
5
6+## 0.1.1.1
7+
8+* Bump base version to work with cabal
9+
6## 0.1.1.0
10## 0.1.1.0
7
11
8* Package is more organized and now has tests and benchmarks separated
12* 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
22
22
23## Features
23## Features
24
24
25−This library offers 4 main matrix programming modules:
25+This library offers 3 main matrix programming modules:
26
26
27- One in which matrices are typed with type level natural numbers;
27- One in which matrices are typed with type level natural numbers;
28- One in which matrices are typed with arbitrary generic data types;
28- One in which matrices are typed with arbitrary generic data types;
laop.cabal+5−4
@@ -1,8 +1,9 @@
1cabal-version: 2.4
1cabal-version: 2.4
2name: laop
2name: laop
3−version: 0.1.1.0
3+version: 0.1.1.1
4−synopsis: See README for more info
4+synopsis: Matrix programming library
5−description: See README for more info
5+description: Matrix programming library that uses a type-safe inductive definition
6+ inspired by the Linear Algebra of Programming
6homepage: https://github.com/bolt12/laop
7homepage: https://github.com/bolt12/laop
7bug-reports: https://github.com/bolt12/laop/issues
8bug-reports: https://github.com/bolt12/laop/issues
8license: MIT
9license: MIT
@@ -22,7 +23,7 @@ source-repository head
22 location: https://github.com/bolt12/laop.git
23 location: https://github.com/bolt12/laop.git
23
24
24common common-options
25common common-options
25− build-depends: base >= 4.12.0.0 && < 4.14,
26+ build-depends: base >= 4.12.0.0 && < 5,
26 deepseq
27 deepseq
27
28
28 ghc-options: -Wall
29 ghc-options: -Wall
src/LAoP/Matrix/Internal.hs+16−66
@@ -243,7 +243,7 @@ type Trivial a = FromNat (Count a) ~ a
243-- class.
243-- class.
244instance (Num e) => Category (Matrix e) where
244instance (Num e) => Category (Matrix e) where
245 type Object (Matrix e) a = (FL a a, Countable a)
245 type Object (Matrix e) a = (FL a a, Countable a)
246− id = iden
246+ id = iden
247 (.) = comp
247 (.) = comp
248
248
249instance NFData e => NFData (Matrix e cols rows) where
249instance NFData e => NFData (Matrix e cols rows) where
@@ -259,7 +259,6 @@ instance Eq e => Eq (Matrix e cols rows) where
259 x@(Join _ _) == y@(Fork _ _) = abideJF x == y
259 x@(Join _ _) == y@(Fork _ _) = abideJF x == y
260
260
261instance Num e => Num (Matrix e cols rows) where
261instance Num e => Num (Matrix e cols rows) where
262−
263 a + b = zipWithM (+) a b
262 a + b = zipWithM (+) a b
264
263
265 a - b = zipWithM (-) a b
264 a - b = zipWithM (-) a b
@@ -326,7 +325,8 @@ instance (FromLists cols ()) => FromLists (Either () cols) () where
326 fromLists [h : t] = Join (One h) (fromLists [t])
325 fromLists [h : t] = Join (One h) (fromLists [t])
327 fromLists _ = error "Wrong dimensions"
326 fromLists _ = error "Wrong dimensions"
328
327
328+instance {-# OVERLAPPABLE #-}
329−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
330 fromLists [l] =
330 fromLists [l] =
331 let rowsA = fromInteger (natVal (Proxy :: Proxy (Count a)))
331 let rowsA = fromInteger (natVal (Proxy :: Proxy (Count a)))
332 in Join (fromLists [take rowsA l]) (fromLists [drop rowsA l])
332 in Join (fromLists [take rowsA l]) (fromLists [drop rowsA l])
@@ -336,13 +336,15 @@ instance (FromLists () rows) => FromLists () (Either () rows) where
336 fromLists ([h] : t) = Fork (One h) (fromLists t)
336 fromLists ([h] : t) = Fork (One h) (fromLists t)
337 fromLists _ = error "Wrong dimensions"
337 fromLists _ = error "Wrong dimensions"
338
338
339+instance {-# OVERLAPPABLE #-}
339−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
340 fromLists l@([_] : _) =
341 fromLists l@([_] : _) =
341 let rowsA = fromInteger (natVal (Proxy :: Proxy (Count a)))
342 let rowsA = fromInteger (natVal (Proxy :: Proxy (Count a)))
342 in Fork (fromLists (take rowsA l)) (fromLists (drop rowsA l))
343 in Fork (fromLists (take rowsA l)) (fromLists (drop rowsA l))
343 fromLists _ = error "Wrong dimensions"
344 fromLists _ = error "Wrong dimensions"
344
345
345−instance (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
346 fromLists l@(h : t) =
348 fromLists l@(h : t) =
347 let lh = length h
349 let lh = length h
348 rowsC = fromInteger (natVal (Proxy :: Proxy (Count c)))
350 rowsC = fromInteger (natVal (Proxy :: Proxy (Count c)))
@@ -369,16 +371,15 @@ matrixBuilder' f =
369matrixBuilder ::
371matrixBuilder ::
370 forall e a b.
372 forall e a b.
371 ( FLN a b,
373 ( FLN a b,
372− CountableN b,
373 Enum a,
374 Enum a,
374 Enum b,
375 Enum b,
375 Bounded a,
376 Bounded a,
376 Bounded b,
377 Bounded b,
377 Eq a,
378 Eq a,
378− CountableDimsN a b
379+ Countable b
379 ) => ((a, b) -> e) -> Matrix e (Normalize a) (Normalize b)
380 ) => ((a, b) -> e) -> Matrix e (Normalize a) (Normalize b)
380matrixBuilder f =
381matrixBuilder f =
381− let r = fromInteger $ natVal (Proxy :: Proxy (Count (Normalize b)))
382+ let r = fromInteger $ natVal (Proxy :: Proxy (Count b))
382 positions = [(a, b) | a <- [minBound .. maxBound], b <- [minBound .. maxBound]]
383 positions = [(a, b) | a <- [minBound .. maxBound], b <- [minBound .. maxBound]]
383 in fromLists . map (map f) . transpose . buildList r $ positions
384 in fromLists . map (map f) . transpose . buildList r $ positions
384 where
385 where
@@ -434,24 +435,7 @@ fromF ::
434 ) =>
435 ) =>
435 (a -> b) ->
436 (a -> b) ->
436 Matrix e (Normalize a) (Normalize b)
437 Matrix e (Normalize a) (Normalize b)
437−fromF f =
438+fromF = fromF'
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
455
439
456-- Conversion
440-- Conversion
457
441
@@ -947,24 +931,7 @@ fromFRel' ::
947 ) =>
931 ) =>
948 (a -> b) ->
932 (a -> b) ->
949 Relation cols rows
933 Relation cols rows
950−fromFRel' f =
934+fromFRel' = fromF'
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
968
935
969-- | Lifts functions to relations with dimensions matching @a@ and @b@
936-- | Lifts functions to relations with dimensions matching @a@ and @b@
970-- cardinality's.
937-- cardinality's.
@@ -972,28 +939,11 @@ fromFRel ::
972 forall a b.
939 forall a b.
973 ( Liftable Boolean a b,
940 ( Liftable Boolean a b,
974 CountableDimsN a b,
941 CountableDimsN a b,
975− FL (Normalize b) (Normalize a)
942+ FLN b a
976 ) =>
943 ) =>
977 (a -> b) ->
944 (a -> b) ->
978 Relation (Normalize a) (Normalize b)
945 Relation (Normalize a) (Normalize b)
979−fromFRel f =
946+fromFRel = fromFRel'
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
997
947
998-- | Lifts a relation function to a Boolean Matrix
948-- | Lifts a relation function to a Boolean Matrix
999toRel ::
949toRel ::
@@ -1003,7 +953,7 @@ toRel ::
1003 Enum a,
953 Enum a,
1004 Enum b,
954 Enum b,
1005 Eq b,
955 Eq b,
1006− CountableDimsN a b,
956+ CountableDims a b,
1007 FLN b a
957 FLN b a
1008 )
958 )
1009 => (a -> b -> Bool) -> Relation (Normalize a) (Normalize b)
959 => (a -> b -> Bool) -> Relation (Normalize a) (Normalize b)
@@ -1012,8 +962,8 @@ toRel f =
1012 maxA = maxBound @a
962 maxA = maxBound @a
1013 minB = minBound @b
963 minB = minBound @b
1014 maxB = maxBound @b
964 maxB = maxBound @b
1015− ccols = fromInteger $ natVal (Proxy :: Proxy (Count (Normalize a)))
965+ ccols = fromInteger $ natVal (Proxy :: Proxy (Count a))
1016− rrows = fromInteger $ natVal (Proxy :: Proxy (Count (Normalize b)))
966+ rrows = fromInteger $ natVal (Proxy :: Proxy (Count b))
1017 elementsA = take ccols [minA .. maxA]
967 elementsA = take ccols [minA .. maxA]
1018 elementsB = take rrows [minB .. maxB]
968 elementsB = take rrows [minB .. maxB]
1019 combinations = (,) <$> elementsA <*> elementsB
969 combinations = (,) <$> elementsA <*> elementsB
src/LAoP/Matrix/Type.hs+2−2
@@ -333,7 +333,7 @@ matrixBuilder ::
333 Bounded a,
333 Bounded a,
334 Bounded b,
334 Bounded b,
335 Eq a,
335 Eq a,
336− CountableDimsN a b
336+ Countable b
337 ) => ((a, b) -> e) -> Matrix e a b
337 ) => ((a, b) -> e) -> Matrix e a b
338matrixBuilder f = M (I.matrixBuilder f)
338matrixBuilder f = M (I.matrixBuilder f)
339
339
@@ -370,7 +370,7 @@ fromF = M . I.fromF
370-- | Lifts relation functions to Boolean Matrix
370-- | Lifts relation functions to Boolean Matrix
371toRel ::
371toRel ::
372 ( Liftable (Natural 0 1) a b,
372 ( Liftable (Natural 0 1) a b,
373− CountableDimsN a b,
373+ CountableDims a b,
374 FLN b a
374 FLN b a
375 ) => (a -> b -> Bool) -> Matrix (Natural 0 1) a b
375 ) => (a -> b -> Bool) -> Matrix (Natural 0 1) a b
376toRel = M . I.toRel
376toRel = M . I.toRel
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