[Haskell-cafe] Re: Why is Day and Month bounded?

2006-07-15 Thread Johan Holmquist
2006/7/14, David House [EMAIL PROTECTED]: On 14/07/06, Johan Holmquist [EMAIL PROTECTED] wrote: You mean [Monday, Tuesday ... Sunday, Monday] ? Actually not. No repetitions. That seems like a very bad idea. '..' normally means 'inclusive', breaking those semantics would be a very weird

[Haskell-cafe] Re: Why is Day and Month bounded?

2006-07-14 Thread Johan Holmquist
I'll answer my own post to elaborate: If Day (and Month) where NOT instances of Bounded, the following would be possible: [Monday .. Sunday] = should return [Monday, Tuesday ... Saturday, Sunday] = but returns [] [Saturday .. Tuesday] = should return [Saturday, Sunday, Monday, Tuesday] = but

Re: [Haskell-cafe] Re: Why is Day and Month bounded?

2006-07-14 Thread Henning Thielemann
On Fri, 14 Jul 2006, Johan Holmquist wrote: I'll answer my own post to elaborate: If Day (and Month) where NOT instances of Bounded, the following would be possible: [Monday .. Sunday] = should return [Monday, Tuesday ... Saturday, Sunday] = but returns [] Why not [Monday, Tuesday

Re: [Haskell-cafe] Re: Why is Day and Month bounded?

2006-07-14 Thread Malcolm Wallace
Johan Holmquist [EMAIL PROTECTED] wrote: If Day (and Month) where NOT instances of Bounded, the following would be possible: [Saturday .. Tuesday] = should return [Saturday, Sunday, Monday, Tuesday] = but returns [] This does seem like a reasonable argument to me. Some enumerations are

Re: [Haskell-cafe] Re: Why is Day and Month bounded?

2006-07-14 Thread Chris Kuklewicz
Try this: module Cycle (Cyclic(..)) where import System.Time import Data.Word import Data.Int class (Eq c,Enum c, Bounded c) = Cyclic c where cyclePeriod :: c - Int cyclePeriod _ = fromEnum (maxBound :: c) - fromEnum (minBound :: c) + 1 succCycle :: c - c succCycle c | c ==

Re: [Haskell-cafe] Re: Why is Day and Month bounded?

2006-07-14 Thread Chris Kuklewicz
Hmmm... I think I should have said: toCycle :: Int - c toCycle = toEnum . (+ (fromEnum (minBound::c))) . (`mod` (cyclePeriod (undefined::c))) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org

Re: [Haskell-cafe] Re: Why is Day and Month bounded?

2006-07-14 Thread Chris Kuklewicz
Okay...final version attached. This one fixes the toCycle bugs and changes from Int to Integer so overflow is no longer an issue. The result of cycleFromThenTo fits what I would expect, but you are free to drop this or adapt it. cycleFrom and cycleFromTo and cycleFromThen are easy, since

[Haskell-cafe] Re: Why is Day and Month bounded?

2006-07-14 Thread Johan Holmquist
Yes, it would be possible to make ones own class and instantiate from that. I was just thinking Day and Month should be cyclic per default. from Henning Thielemann: Since the days are cycling, what is more natural about your result compared to my one? I would prefer the one without any

Re: [Haskell-cafe] Re: Why is Day and Month bounded?

2006-07-14 Thread Henning Thielemann
On Fri, 14 Jul 2006, Johan Holmquist wrote: from Henning Thielemann: Since the days are cycling, what is more natural about your result compared to my one? I would prefer the one without any repetitions. I assume the Bounded instance exists in order to allow loops like liftM2 (,)

Re: [Haskell-cafe] Re: Why is Day and Month bounded?

2006-07-14 Thread David Roundy
Interestingly, your Cyclic class idea may have practical purposes beyond enumeration. Integers modulo some number are also cyclical, and can come in very handy. In fact, raw unsigned ints are modulo 2^32 (or something like that), so they really ought (under one interpretation) to be members of

Re: [Haskell-cafe] Re: Why is Day and Month bounded?

2006-07-14 Thread David House
On 14/07/06, David Roundy [EMAIL PROTECTED] wrote: Anyhow, just thought I'd mention that this isn't useful only for ordinary cyclic objects like dates. Correct. Which is why Chris Kuklewicz included instances for, e.g., Int :) I think this would be a great class to have in the standard libs.

Re: [Haskell-cafe] Re: Why is Day and Month bounded?

2006-07-14 Thread David House
On 14/07/06, Johan Holmquist [EMAIL PROTECTED] wrote: You mean [Monday, Tuesday ... Sunday, Monday] ? Actually not. No repetitions. That seems like a very bad idea. '..' normally means 'inclusive', breaking those semantics would be a very weird thing to do, and breaks the principle of least

Re: [Haskell-cafe] Re: Why is Day and Month bounded?

2006-07-14 Thread Chris Kuklewicz
David House wrote: On 14/07/06, David Roundy [EMAIL PROTECTED] wrote: Anyhow, just thought I'd mention that this isn't useful only for ordinary cyclic objects like dates. Correct. Which is why Chris Kuklewicz included instances for, e.g., Int :) And the new version takes everything to

Re: [Haskell-cafe] Re: Why is Day and Month bounded?

2006-07-14 Thread David Roundy
On Fri, Jul 14, 2006 at 02:28:20PM +0100, David House wrote: On 14/07/06, David Roundy [EMAIL PROTECTED] wrote: Anyhow, just thought I'd mention that this isn't useful only for ordinary cyclic objects like dates. Correct. Which is why Chris Kuklewicz included instances for, e.g., Int :) Ah,