Skip to content
This repository has been archived by the owner on Sep 20, 2023. It is now read-only.

How is CountOf intended to be used? #372

Open
ocharles opened this issue Jun 27, 2017 · 3 comments
Open

How is CountOf intended to be used? #372

ocharles opened this issue Jun 27, 2017 · 3 comments

Comments

@ocharles
Copy link

length returns a CountOf value, but these seem pretty painful to work with. In some code I'm working with, I need to build a count of bytes to supply to OpenGL. This means multiplying a CountOf by the size in bytes of a single element, and then turning the whole thing to a Int, but there is no easy way to do this (there is no eliminator for CountOf, for one).

@ndmitchell
Copy link
Contributor

See also #368 - recommended adding countOf :: CountOf a -> Int.

@ocharles
Copy link
Author

Nice, thanks - seems to be the same problem.

@vincenthz
Copy link
Member

so the idea of CountOf is to be able to distinguish stuff like "a number of a" and "a number of bytes".
The external interface of CountOf is a bit crappy at the moment but I think it has some merits. This found couple of internals bugs at compilation time where the number units had not been converted properly because of using Int before.

Also CountOf doesn't have a IsNegative instance, so you can write negative literal for it, and potentially the type inside could be unsigned in the future, preventing by type to e.g. take -3

I think we just need to put some lipstick on the interfaces (and here suggestions are more than welcome to make it less painful to work with; One of the issue is that the current state of affair (haskell / base) is quite poor in term of integral APIs, so we don't have anything useful to re-use.

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

No branches or pull requests

3 participants