-
Notifications
You must be signed in to change notification settings - Fork 19
Open
Description
Every finite type can be ordered (somehow). Here's one way to express that:
class (Universe a, Coercible a (Ordered a), Ord (Ordered a)) => Finite a where
type Ordered a
type Ordered a = a
universeS :: Set (Ordered a)
universeS = fromList (coerce $ universeF @a)
universeF :: [a]
universeF = coerce . toList $ universeS @aAnother option would be to allow an arbitrary Iso' between a and a (possibly very different) Ordered a, which might be better if the ordering on Ordered a can't be expressed efficiently by directly comparing elements of a.
class (Universe a, Ord (Ordered a)) => Finite a where
type Ordered a
type Ordered a = a
ordering :: Iso' a (Ordered a)
default ordering :: Coercible a (Ordered a) => Iso' a (Ordered a)
ordering = coerced
universeS :: Set (Ordered a)
universeS = fromList (map (view ordering) (universeF @a))
universeF :: [a]
universeF = universe
-- A default definition of `universe` or `universeF` in terms of `universeF`
universeFfromS :: forall a. Finite a => [a]
universeFfromS = map (view (from ordering)) . toList $ universeS @aReactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels