Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
JordanMartinez opened this issue May 18, 2022 · 0 comments
Open

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

JordanMartinez opened this issue May 18, 2022 · 0 comments

Comments

@JordanMartinez
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant