@@ -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,7 +259,6 @@ 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−
263262 a + b = zipWithM (+) a b
264263
265264 a - b = zipWithM (-) a b
@@ -326,7 +325,8 @@ instance (FromLists cols ()) => FromLists (Either () cols) () where
326325 fromLists [h : t] = Join (One h) (fromLists [t])
327326 fromLists _ = error "Wrong dimensions"
328327
329−instance {-# OVERLAPPABLE #-} (FromLists a (), FromLists b (), Countable a) => FromLists (Either a b) () where
328+instance {-# OVERLAPPABLE #-}
329+ (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,13 +336,15 @@ 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 #-} (FromLists () a, FromLists () b, Countable a) => FromLists () (Either a b) where
339+instance {-# OVERLAPPABLE #-}
340+ (FromLists () a, FromLists () b, Countable a) => FromLists () (Either a b) where
340341 fromLists l@([_] : _) =
341342 let rowsA = fromInteger (natVal (Proxy :: Proxy (Count a)))
342343 in Fork (fromLists (take rowsA l)) (fromLists (drop rowsA l))
343344 fromLists _ = error "Wrong dimensions"
344345
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
346348 fromLists l@(h : t) =
347349 let lh = length h
348350 rowsC = fromInteger (natVal (Proxy :: Proxy (Count c)))
@@ -428,29 +430,12 @@ fromF' f =
428430fromF ::
429431 forall a b e.
430432 ( Liftable e a b,
431− CountableDims a b,
433+ CountableDimsN a b,
432434 FLN b a
433435 ) =>
434436 (a -> b) ->
435437 Matrix e (Normalize a) (Normalize b)
436−fromF f =
437− let minA = minBound @a
438− maxA = maxBound @a
439− minB = minBound @b
440− maxB = maxBound @b
441− ccols = fromInteger $ natVal (Proxy :: Proxy (Count a))
442− rrows = fromInteger $ natVal (Proxy :: Proxy (Count b))
443− elementsA = take ccols [minA .. maxA]
444− elementsB = take rrows [minB .. maxB]
445− combinations = (,) <$> elementsA <*> elementsB
446− combAp = map snd . sort . map (\(a, b) -> if f a == b
447− then ((fromEnum a, fromEnum b), 1)
448− else ((fromEnum a, fromEnum b), 0)) $ combinations
449− mList = buildList combAp rrows
450− in tr $ fromLists mList
451− where
452− buildList [] _ = []
453− buildList l r = take r l : buildList (drop r l) r
438+fromF = fromF'
454439
455440-- Conversion
456441
@@ -946,53 +931,19 @@ fromFRel' ::
946931 ) =>
947932 (a -> b) ->
948933 Relation cols rows
949−fromFRel' f =
950− let minA = minBound @a
951− maxA = maxBound @a
952− minB = minBound @b
953− maxB = maxBound @b
954− ccols = fromInteger $ natVal (Proxy :: Proxy (Count cols))
955− rrows = fromInteger $ natVal (Proxy :: Proxy (Count rows))
956− elementsA = take ccols [minA .. maxA]
957− elementsB = take rrows [minB .. maxB]
958− combinations = (,) <$> elementsA <*> elementsB
959− combAp = map snd . sort . map (\(a, b) -> if f a == b
960− then ((fromEnum a, fromEnum b), nat 1)
961− else ((fromEnum a, fromEnum b), nat 0)) $ combinations
962− mList = buildList combAp rrows
963− in tr $ fromLists mList
964− where
965− buildList [] _ = []
966− buildList l r = take r l : buildList (drop r l) r
934+fromFRel' = fromF'
967935
968936-- | Lifts functions to relations with dimensions matching @a@ and @b@
969937-- cardinality's.
970938fromFRel ::
971939 forall a b.
972940 ( Liftable Boolean a b,
973− CountableDims a b,
974− FL (Normalize b) (Normalize a)
941+ CountableDimsN a b,
942+ FLN b a
975943 ) =>
976944 (a -> b) ->
977945 Relation (Normalize a) (Normalize b)
978−fromFRel f =
979− let minA = minBound @a
980− maxA = maxBound @a
981− minB = minBound @b
982− maxB = maxBound @b
983− ccols = fromInteger $ natVal (Proxy :: Proxy (Count a))
984− rrows = fromInteger $ natVal (Proxy :: Proxy (Count b))
985− elementsA = take ccols [minA .. maxA]
986− elementsB = take rrows [minB .. maxB]
987− combinations = (,) <$> elementsA <*> elementsB
988− combAp = map snd . sort . map (\(a, b) -> if f a == b
989− then ((fromEnum a, fromEnum b), nat 1)
990− else ((fromEnum a, fromEnum b), nat 0)) $ combinations
991− mList = buildList combAp rrows
992− in tr $ fromLists mList
993− where
994− buildList [] _ = []
995− buildList l r = take r l : buildList (drop r l) r
946+fromFRel = fromFRel'
996947
997948-- | Lifts a relation function to a Boolean Matrix
998949toRel ::