Hi,
I've been playing around with some toy code that overlaps with some of the problems this library solves. In looking at it, I had a few questions:
-
cardinality has type proxy a -> Integer. Should it be proxy a -> Natural instead?
-
universe has type [a]. Sometimes you may want the inhabitant at an index i. With the current API, I guess you would do genericIndex universe i. Would it make sense to have some function foo with type Natural -> Maybe a or Natural -> a, too? universe could perhaps have a default implementation in terms of this function, e.g.
universe = takeWhile isJust $ map foo [1..]
My feeling is that a class-specific implementation of Natural -> Maybe a could be more performant than genericIndex universe i.
-
Would it make sense to have a function Maybe a -> Natural on Universe or a related class? (For more context, my dissatisfaction with Enum's toEnum and fromEnum using Int led me here...)
-
Finite says
Creating an instance of this class is a declaration that your universe eventually ends.
This seems very similar to Bounded. Would it make sense to be able to recover something like a minBound and maxBound with this class? Such that
minBound == universe `genericIndex` 0
maxBound == universe `genericIndex` (cardinality (Proxy :: Proxy a))
Although there is a law about universeF terminating, would such bounds with laws like the above give stronger guarantees about Finite? I worry that universeF versus universe don't tell me very much, since they have the same type [a].
-
Would an Infinite class make sense, e.g.
class Universe a => Infinite a where
infinite :: Stream a
Reading this library, I see Universe could be finite or infinite, based on the [a] API. I see Finite should be finite (although I must trust universeF terminates). Something like infinite with a Stream a-based API could make clear that the Stream returned by infinite does not terminate. There could also be a law
universe == toList infinite
Thanks for your consideration,
Mark
Hi,
I've been playing around with some toy code that overlaps with some of the problems this library solves. In looking at it, I had a few questions:
cardinalityhas typeproxy a -> Integer. Should it beproxy a -> Naturalinstead?universehas type[a]. Sometimes you may want the inhabitant at an indexi. With the current API, I guess you would dogenericIndex universe i. Would it make sense to have some functionfoowith typeNatural -> Maybe aorNatural -> a, too?universecould perhaps have a default implementation in terms of this function, e.g.My feeling is that a class-specific implementation of
Natural -> Maybe acould be more performant thangenericIndex universe i.Would it make sense to have a function
Maybe a -> NaturalonUniverseor a related class? (For more context, my dissatisfaction with Enum'stoEnumandfromEnumusingIntled me here...)FinitesaysThis seems very similar to
Bounded. Would it make sense to be able to recover something like aminBoundandmaxBoundwith this class? Such thatAlthough there is a law about
universeFterminating, would such bounds with laws like the above give stronger guarantees aboutFinite? I worry thatuniverseFversusuniversedon't tell me very much, since they have the same type[a].Would an
Infiniteclass make sense, e.g.Reading this library, I see
Universecould be finite or infinite, based on the[a]API. I seeFiniteshould be finite (although I must trustuniverseFterminates). Something likeinfinitewith aStream a-based API could make clear that theStreamreturned byinfinitedoes not terminate. There could also be a lawuniverse == toList infiniteThanks for your consideration,
Mark