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

enumFrom errors for Index 0 #2851

Open
kleinreact opened this issue Nov 27, 2024 · 4 comments
Open

enumFrom errors for Index 0 #2851

kleinreact opened this issue Nov 27, 2024 · 4 comments
Labels

Comments

@kleinreact
Copy link
Member

enumFrom and alike should not error for Index 0. They should return the empty list instead.

clashi> enumFrom (undefined :: Index 0)
*** Exception: X: maxBound of 'Index 0' is undefined
@kleinreact kleinreact added the bug label Nov 27, 2024
@christiaanb
Copy link
Member

I think the definition of Enum isn't clear that it should not error in this case, or that it should return the empty list. I agree it would be nice and that we should probably change the implementation to behave accordingly.

@christiaanb
Copy link
Member

I mean, it even states https://hackage.haskell.org/package/base-4.20.0.1/docs/Data-Enum.html#v:enumFrom

a possible implementation being enumFrom n = n : enumFrom (succ n)

which would have the following reduction to WHNF:

enumFrom (undefined :: Index 0)
==>
(undefined :: Index 0) : enumFrom (succ (undefined :: Index 0))

@kleinreact
Copy link
Member Author

You are right, there is no requirement that enumFrom should not error in that case, but producing the empty list seems to be the "more correct" solution to me, to be honest. I just recognized this behavior by accident and thought that an error-less solution might be the better option here.

@DigitalBrains1
Copy link
Member

I agree that the empty list is the desirable outcome here, even though there are no Haskell laws preventing the current implementation.

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

No branches or pull requests

3 participants