on master help sign in
Fix Powerset newtype wrapper
ab2a4daArmando Santos
src/LAoP/Matrix/Internal.hs+1−1
@@ -176,7 +176,7 @@ deriving instance (Show e) => Show (Matrix e cols rows)
176-- 'Generic' instance.
176-- 'Generic' instance.
177type family Count (d :: Type) :: Nat where
177type family Count (d :: Type) :: Nat where
178 Count (Natural n m) = (m - n) + 1
178 Count (Natural n m) = (m - n) + 1
179− Count (Powerset a) = (^) (Count a) (Count a)
179+ Count (List a) = (^) 2 (Count a)
180 Count (Either a b) = (+) (Count a) (Count b)
180 Count (Either a b) = (+) (Count a) (Count b)
181 Count (a, b) = (*) (Count a) (Count b)
181 Count (a, b) = (*) (Count a) (Count b)
182 Count (a -> b) = (^) (Count b) (Count a)
182 Count (a -> b) = (^) (Count b) (Count a)
src/LAoP/Relation/Internal.hs+9−8
@@ -185,6 +185,7 @@ import GHC.TypeLits
185
185
186-- | Boolean type synonym for working with boolean matrices
186-- | Boolean type synonym for working with boolean matrices
187type Boolean = Natural 0 1
187type Boolean = Natural 0 1
188+type Powerset a = List (List a)
188
189
189-- | Relation data type.
190-- | Relation data type.
190newtype Relation a b = R (I.Matrix Boolean (I.Normalize a) (I.Normalize b))
191newtype Relation a b = R (I.Matrix Boolean (I.Normalize a) (I.Normalize b))
@@ -354,23 +355,23 @@ pt ::
354 FromListsN a One,
355 FromListsN a One,
355 FromListsN b One
356 FromListsN b One
356 )
357 )
357− => Relation a b -> (a -> Powerset b)
358+ => Relation a b -> (a -> List b)
358pt r a =
359pt r a =
359− let (PS lb) = maxBound
360+ let (L lb) = maxBound
360− in PS [ b | b <- lb, toBool (pointAp a b r) ]
361+ in L [ b | b <- lb, toBool (pointAp a b r) ]
361
362
362-- | Belongs relation
363-- | Belongs relation
363belongs ::
364belongs ::
364 ( Bounded a,
365 ( Bounded a,
365 Enum a,
366 Enum a,
366 Eq a,
367 Eq a,
367− CountableDimensionsN (Powerset a) a,
368+ CountableDimensionsN (List a) a,
368− FromListsN a (Powerset a)
369+ FromListsN a (List a)
369 )
370 )
370− => Relation (Powerset a) a
371+ => Relation (List a) a
371−belongs = toRel (flip elemR)
372+belongs = toRel elemR
372 where
373 where
373− elemR x (PS l) = x `elem` l
374+ elemR (L l) x = x `elem` l
374
375
375-- Zeros Matrix
376-- Zeros Matrix
376
377
src/LAoP/Utils.hs+1−1
@@ -96,7 +96,7 @@ module LAoP.Utils
96 coerceNat3,
96 coerceNat3,
97
97
98 -- * Powerset data type
98 -- * Powerset data type
99− Powerset (..)
99+ List (..)
100 )
100 )
101where
101where
102
102
src/LAoP/Utils/Internal.hs+9−9
@@ -88,7 +88,7 @@ module LAoP.Utils.Internal
88 coerceNat3,
88 coerceNat3,
89
89
90 -- * Powerset data type
90 -- * Powerset data type
91− Powerset (..)
91+ List (..)
92 )
92 )
93where
93where
94
94
@@ -207,7 +207,7 @@ instance
207--
207--
208-- This data type is a newtype wrapper around '[]'. This exists in order to
208-- This data type is a newtype wrapper around '[]'. This exists in order to
209-- implement an 'Enum' and 'Bounded' instance that cannot be harmful for the outside.
209-- 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]
211 deriving (Eq, Show, Read)
211 deriving (Eq, Show, Read)
212
212
213powerset :: [a] -> [[a]]
213powerset :: [a] -> [[a]]
@@ -217,22 +217,22 @@ powerset (x:xs) = powerset xs ++ [x:ps | ps <- powerset xs]
217instance
217instance
218 ( Enum a,
218 ( Enum a,
219 Bounded a
219 Bounded a
220− ) => Bounded (Powerset a)
220+ ) => Bounded (List a)
221 where
221 where
222− minBound = PS []
222+ minBound = L []
223− maxBound = PS [minBound .. maxBound]
223+ maxBound = L [minBound .. maxBound]
224
224
225instance
225instance
226 ( Bounded a,
226 ( Bounded a,
227 Enum a,
227 Enum a,
228 Eq a
228 Eq a
229− ) => Enum (Powerset a)
229+ ) => Enum (List a)
230 where
230 where
231 toEnum i =
231 toEnum i =
232 let as = [minBound .. maxBound]
232 let as = [minBound .. maxBound]
233− in PS (powerset as !! i)
233+ in L (powerset as !! i)
234
234
235− fromEnum (PS []) = 0
235+ fromEnum (L []) = 0
236− fromEnum (PS x) =
236+ fromEnum (L x) =
237 let as = [minBound .. maxBound]
237 let as = [minBound .. maxBound]
238 in fromMaybe (error "Does not exist") $ elemIndex x (powerset as)
238 in fromMaybe (error "Does not exist") $ elemIndex x (powerset as)