Skip to content

Define BoundedEnum-like class using type-level Ints #54

Open
@JordanMartinez

Description

@JordanMartinez

With type-level ints, we can actually specify what the bounds are for a given type. For example...

class (Bounded a, Enum a) <= BoundedEnumTL min step max a where
  toEnumTL :: Proxy Int -> a

This would enable one to use toEnum without incurring the Maybe wrapper.

instance BoundedEnumTL 0 1 23 Hour where
  toEnumTL p = Hour $ reflectType p

-- cardinality could likely be calculated
cardinalityTL :: BoundedEnumTL min step max => ... => Proxy Int

toEnumTL (Proxy :: Proxy 4) == Hour 4
toEnumTL (Proxy :: Proxy 26) -- compiler error

See also purescript/purescript-datetime#96

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions