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

Purpose of this library #1

Closed
Kleidukos opened this issue Apr 14, 2022 · 3 comments
Closed

Purpose of this library #1

Kleidukos opened this issue Apr 14, 2022 · 3 comments

Comments

@Kleidukos
Copy link

Hi, I'm reading the documentation of this library and I have a hard time determining the purpose of the Pos datatype, compared to Word. Is there some advantage that I missed?

@gbwey
Copy link
Owner

gbwey commented Apr 15, 2022

Good question. The main difference with Word is that Pos doesn't allow zero and does not provide a Num instance.
I excluded the Num instance so there would be fewer potential runtime errors arising from using fromIntegral/subtraction/negation.

Pos is designed to work with nonempty containers and in configuration where zero is invalid.
Examples:

  • The cybus package uses the Pos type with multidimensional arrays and indices where each dimension of the array is nonzero and the number of dimensions is nonzero
  • It is also used in the primus package for dealing with nonempty containers.
  • I use it in configuration where the number of cpus cannot be zero when running concurrent tasks; or where duration of a thread delay must be greater than zero.

Not having a Num instance for Pos is annoying, but the primus package provides a Num1 class that is a safer alternative to Num that respects the bounds of those numbers. So there are Num1 instances for Natural/Word/Pos etc.

@Kleidukos
Copy link
Author

Awesome, thank you very much for this explanation!

@gbwey
Copy link
Owner

gbwey commented Apr 16, 2022

Glad that helped.

@gbwey gbwey closed this as completed Apr 16, 2022
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

2 participants