on master help sign in
Fix Powerset newtype wrapper
commitab2a4da70646301c5caecfa6466d862ab8314855 authorArmando Santos <armandoifsantos@gmail.com> dateSat 1 Feb 2020, 21:11 (7 years ago) parent9b8a345
4 files changed+20−19
src/LAoP/Matrix/Internal.hs+1−1 src/LAoP/Relation/Internal.hs+9−8 src/LAoP/Utils.hs+1−1 src/LAoP/Utils/Internal.hs+9−9
src/LAoP/Matrix/Internal.hs+1−1
@@ -176,7 +176,7 @@ deriving instance (Show e) => Show (Matrix e cols rows)
176176-- 'Generic' instance.
177177type family Count (d :: Type) :: Nat where
178178 Count (Natural n m) = (m - n) + 1
179− Count (Powerset a) = (^) (Count a) (Count a)
179+ Count (List a) = (^) 2 (Count a)
180180 Count (Either a b) = (+) (Count a) (Count b)
181181 Count (a, b) = (*) (Count a) (Count b)
182182 Count (a -> b) = (^) (Count b) (Count a)
src/LAoP/Relation/Internal.hs+9−8
@@ -185,6 +185,7 @@ import GHC.TypeLits
185185
186186-- | Boolean type synonym for working with boolean matrices
187187type Boolean = Natural 0 1
188+type Powerset a = List (List a)
188189
189190-- | Relation data type.
190191newtype Relation a b = R (I.Matrix Boolean (I.Normalize a) (I.Normalize b))
@@ -354,23 +355,23 @@ pt ::
354355 FromListsN a One,
355356 FromListsN b One
356357 )
357− => Relation a b -> (a -> Powerset b)
358+ => Relation a b -> (a -> List b)
358359pt r a =
359− let (PS lb) = maxBound
360− in PS [ b | b <- lb, toBool (pointAp a b r) ]
360+ let (L lb) = maxBound
361+ in L [ b | b <- lb, toBool (pointAp a b r) ]
361362
362363-- | Belongs relation
363364belongs ::
364365 ( Bounded a,
365366 Enum a,
366367 Eq a,
367− CountableDimensionsN (Powerset a) a,
368− FromListsN a (Powerset a)
368+ CountableDimensionsN (List a) a,
369+ FromListsN a (List a)
369370 )
370− => Relation (Powerset a) a
371−belongs = toRel (flip elemR)
371+ => Relation (List a) a
372+belongs = toRel elemR
372373 where
373− elemR x (PS l) = x `elem` l
374+ elemR (L l) x = x `elem` l
374375
375376-- Zeros Matrix
376377
src/LAoP/Utils.hs+1−1
@@ -96,7 +96,7 @@ module LAoP.Utils
9696 coerceNat3,
9797
9898 -- * Powerset data type
99− Powerset (..)
99+ List (..)
100100 )
101101where
102102
src/LAoP/Utils/Internal.hs+9−9
@@ -88,7 +88,7 @@ module LAoP.Utils.Internal
8888 coerceNat3,
8989
9090 -- * Powerset data type
91− Powerset (..)
91+ List (..)
9292 )
9393where
9494
@@ -207,7 +207,7 @@ instance
207207--
208208-- This data type is a newtype wrapper around '[]'. This exists in order to
209209-- implement an 'Enum' and 'Bounded' instance that cannot be harmful for the outside.
210−newtype Powerset a = PS [a]
210+newtype List a = L [a]
211211 deriving (Eq, Show, Read)
212212
213213powerset :: [a] -> [[a]]
@@ -217,22 +217,22 @@ powerset (x:xs) = powerset xs ++ [x:ps | ps <- powerset xs]
217217instance
218218 ( Enum a,
219219 Bounded a
220− ) => Bounded (Powerset a)
220+ ) => Bounded (List a)
221221 where
222− minBound = PS []
223− maxBound = PS [minBound .. maxBound]
222+ minBound = L []
223+ maxBound = L [minBound .. maxBound]
224224
225225instance
226226 ( Bounded a,
227227 Enum a,
228228 Eq a
229− ) => Enum (Powerset a)
229+ ) => Enum (List a)
230230 where
231231 toEnum i =
232232 let as = [minBound .. maxBound]
233− in PS (powerset as !! i)
233+ in L (powerset as !! i)
234234
235− fromEnum (PS []) = 0
236− fromEnum (PS x) =
235+ fromEnum (L []) = 0
236+ fromEnum (L x) =
237237 let as = [minBound .. maxBound]
238238 in fromMaybe (error "Does not exist") $ elemIndex x (powerset as)