What is the good way to work with list comprehension and UTCTime?

Hi, Simple usage, I could make an instance of Enum to UTCTime, so [utcTime..] could work. But that is so stiff. How if sometimes I want to step by 1 min, sometimes I want to step by 1 sec? So I think some way like [ t | addUTCTime last 60 ] could be nice. But I cannot figure it out.... Any idea? -- 竹密岂妨流水过 山高哪阻野云飞 And for G+, please use magiclouds#gmail.com.

On Thu, Sep 13, 2012 at 10:29 PM, Magicloud Magiclouds < magicloud.magiclouds@gmail.com> wrote:
Hi, Simple usage, I could make an instance of Enum to UTCTime, so [utcTime..] could work. But that is so stiff. How if sometimes I want to step by 1 min, sometimes I want to step by 1 sec? So I think some way like [ t | addUTCTime last 60 ] could be nice. But I cannot figure it out.... Any idea?
Try using Prelude.iterate. -Karl

Consider using the time-lens package. import Data.Time.Lens import Data.Lens.Common List comprehension style: [modL seconds (+ fromIntegral n) t | n <- [0..]] [modL minutes (+ n) t | n <- [0..]] (you need fromIntegral for seconds, because it is of fractional type in Data.Time). iterate style, as suggested by Karl: iterate (seconds ^+= 1) t iterate (minutes ^+= 1) t On Fri, Sep 14, 2012 at 7:29 AM, Magicloud Magiclouds < magicloud.magiclouds@gmail.com> wrote:
Hi, Simple usage, I could make an instance of Enum to UTCTime, so [utcTime..] could work. But that is so stiff. How if sometimes I want to step by 1 min, sometimes I want to step by 1 sec? So I think some way like [ t | addUTCTime last 60 ] could be nice. But I cannot figure it out.... Any idea? -- 竹密岂妨流水过 山高哪阻野云飞
And for G+, please use magiclouds#gmail.com.
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

This is nice. Thanks to all.
On Fri, Sep 14, 2012 at 4:03 PM, Roman Cheplyaka
Consider using the time-lens package.
import Data.Time.Lens import Data.Lens.Common
List comprehension style:
[modL seconds (+ fromIntegral n) t | n <- [0..]] [modL minutes (+ n) t | n <- [0..]]
(you need fromIntegral for seconds, because it is of fractional type in Data.Time).
iterate style, as suggested by Karl:
iterate (seconds ^+= 1) t iterate (minutes ^+= 1) t
On Fri, Sep 14, 2012 at 7:29 AM, Magicloud Magiclouds
wrote: Hi, Simple usage, I could make an instance of Enum to UTCTime, so [utcTime..] could work. But that is so stiff. How if sometimes I want to step by 1 min, sometimes I want to step by 1 sec? So I think some way like [ t | addUTCTime last 60 ] could be nice. But I cannot figure it out.... Any idea? -- 竹密岂妨流水过 山高哪阻野云飞
And for G+, please use magiclouds#gmail.com.
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
-- 竹密岂妨流水过 山高哪阻野云飞 And for G+, please use magiclouds#gmail.com.
participants (3)
-
Karl Voelker
-
Magicloud Magiclouds
-
Roman Cheplyaka