Skip to content

Consider a SmallBounded type #38

Open
@bbarker

Description

@bbarker

As an alternative to #35 that is a bit easier to deal with but slightly less safe (though unless you are doing some crazy stuff, should be fine most of the time), I would like to ask if we could do the following, and thus resurrect e.g. boundedEnumMaybe:

-- | A lawful class to denote Cardinality a << Cardinality Int
class Bounded a <= SmallBounded a

instance boundedEnumMaybe :: (SmallBounded a, BoundedEnum a)
  => BoundedEnum (MaybeWrapped a) where
    cardinality = Cardinality $ unwrap (cardinality :: Cardinality a) + 1
    toEnum 0 = wrap  Nothing
    toEnum n = wrap $ Just <$> toEnum (n - 1)
    fromEnum Nothing = 0
    fromEnum (Just e) = fromEnum e + 1

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: needs more infoThis issue needs more info before any action can be done.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions