Re: [Haskell-cafe] Natural Numbers: Best implementation?

On 2009 Mar 12, at 22:54, Mark Spezzano wrote:
I was wondering what the best way to implement Natural number would be. Is there a package which already does this?
type-level on Hackage.
2. Use the type data Natural = Zero | Succ !Natural
One of the reasons people use type-level naturals is to get laziness; you've made this strict. Is there a reason? -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH

Am Freitag, 13. März 2009 04:53 schrieb Brandon S. Allbery KF8NH:
On 2009 Mar 12, at 22:54, Mark Spezzano wrote:
I was wondering what the best way to implement Natural number would be. Is there a package which already does this?
type-level on Hackage.
I think, the original poster wanted value-level naturals, not type-level naturals.
2. Use the type data Natural = Zero | Succ !Natural
One of the reasons people use type-level naturals is to get laziness; you've made this strict. Is there a reason?
Do you really mean type-level naturals? The following is a definition of value-level naturals: data Natural = Zero | Succ Natural Type-level naturals would be defined like this: data Zero data Succ nat Best wishes, Wolfgang

On 2009 Mar 13, at 4:25, Wolfgang Jeltsch wrote:
Am Freitag, 13. März 2009 04:53 schrieb Brandon S. Allbery KF8NH:
On 2009 Mar 12, at 22:54, Mark Spezzano wrote:
I was wondering what the best way to implement Natural number would be. Is there a package which already does this?
type-level on Hackage.
I think, the original poster wanted value-level naturals, not type- level naturals.
My (possibly incorrect) understanding was that value-level naturals required runtime range checks, whereas type-level naturals allowed you to validate them at compile time. I thought I'd mentioned that in my response, contrasting type-level naturals with value-level newtypes and other implementations. -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH
participants (2)
-
Brandon S. Allbery KF8NH
-
Wolfgang Jeltsch