Skip to content

Questions #29

@markandrus

Description

@markandrus

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:

  1. cardinality has type proxy a -> Integer. Should it be proxy a -> Natural instead?

  2. 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.

  3. 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...)

  4. 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].

  5. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions