Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org
You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than "Re: Contents of Beginners digest..." Today's Topics: 1. Re: iterating over a range of dates (Alexander Dunlap) 2. Re: iterating over a range of dates (David McBride) 3. Re: iterating over a range of dates (David McBride) 4. Fwd: Can i define a record without defining access method. (David McBride) 5. Re: Can i define a record without defining access method. (Brandon Allbery) ---------------------------------------------------------------------- Message: 1 Date: Sat, 9 Jul 2011 09:52:22 -0700 From: Alexander Dunlap <alexander.dun...@gmail.com> Subject: Re: [Haskell-beginners] iterating over a range of dates To: Rolf Hanson <rolf.han...@gmail.com> Cc: beginners@haskell.org Message-ID: <cakdsjne+ggkp44panlfdr0ozypc-auc5yacmttw5kfwxmbh...@mail.gmail.com> Content-Type: text/plain; charset=UTF-8 On 9 July 2011 09:33, Rolf Hanson <rolf.han...@gmail.com> wrote: > Hi, I'm trying to iterate over a range of dates and print them out. > Here's how I am doing it in Ruby: > > 'require 'date' > > now ? ? ?= Date.parse('2011-07-11') > end_date = Date.parse('2011-12-31') > > (now..end_date).each do |d| > ?# print out a date that looks like: > ?# Monday, July 11, 2011 > ?puts "#{d.strftime('%A, %B %d, %Y')}" > end > > I've been looking at the docs for Data.Time.Format and Data.Time.Calendar and > am a bit puzzled at where to begin. Anyone have ideas? I've not found many > (any?) examples of time and date manipulation in Haskell. > > RW > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://www.haskell.org/mailman/listinfo/beginners > A good starting point would be the Enum instance of Day in Data.Time.Calendar, which lets you use the [a..b] syntactic sugar to do a range. fromGregorian will get you from a year, month, and day to the Day type: Prelude Data.Time.Calendar> [fromGregorian 2011 07 09..fromGregorian 2011 07 20] [2011-07-09,2011-07-10,2011-07-11,2011-07-12,2011-07-13,2011-07-14,2011-07-15,2011-07-16,2011-07-17,2011-07-18,2011-07-19,2011-07-20] This is equivalent to enumFromTo (fromGregorian 2011 07 09) (fromGregorian 2011 07 20) formatTime in Data.Time.Format will probably get you the rest of the way. Hope that helps, Alex ------------------------------ Message: 2 Date: Sat, 9 Jul 2011 13:14:15 -0400 From: David McBride <dmcbr...@neondsl.com> Subject: Re: [Haskell-beginners] iterating over a range of dates To: beginners@haskell.org Message-ID: <can+tr406hxqnu3rzkfsxpfxnme5siffjcvao4g0xuobcebp...@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1 import Data.Time.LocalTime import Data.Time.Format import System.Locale now :: Maybe LocalTime -- Change this to get different types of values (days, etc). now = parseTime defaultTimeLocale "%F" "2011-07-11" main = putStrLn $ case now of Nothing -> "Failed Parse" Just x -> (formatTime defaultTimeLocale "%F" x) On Sat, Jul 9, 2011 at 12:33 PM, Rolf Hanson <rolf.han...@gmail.com> wrote: > Hi, I'm trying to iterate over a range of dates and print them out. > Here's how I am doing it in Ruby: > > 'require 'date' > > now ? ? ?= Date.parse('2011-07-11') > end_date = Date.parse('2011-12-31') > > (now..end_date).each do |d| > ?# print out a date that looks like: > ?# Monday, July 11, 2011 > ?puts "#{d.strftime('%A, %B %d, %Y')}" > end > > I've been looking at the docs for Data.Time.Format and Data.Time.Calendar and > am a bit puzzled at where to begin. Anyone have ideas? I've not found many > (any?) examples of time and date manipulation in Haskell. > > RW > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://www.haskell.org/mailman/listinfo/beginners > ------------------------------ Message: 3 Date: Sat, 9 Jul 2011 13:27:44 -0400 From: David McBride <dmcbr...@neondsl.com> Subject: Re: [Haskell-beginners] iterating over a range of dates To: beginners@haskell.org Message-ID: <can+tr40apwsd3ejf9mh5xqcvlban8_b9n3bghvo5magnnkm...@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1 Sorry, I misunderstood your ruby. The Day datatype has an ordinal instance for this purpose and also a convenient show instance in case you wanted it. import Data.Time.Calendar import Data.Time.Format import System.Locale main = let (Just now) = (parseTime defaultTimeLocale "%F" "2011-07-11" :: Maybe Day) (Just end) = (parseTime defaultTimeLocale "%F" "2011-07-15" :: Maybe Day) in mapM_ print [now..end] On Sat, Jul 9, 2011 at 1:14 PM, David McBride <dmcbr...@neondsl.com> wrote: > import Data.Time.LocalTime > import Data.Time.Format > import System.Locale > > now :: Maybe LocalTime -- Change this to get different types of values > (days, etc). > now = parseTime defaultTimeLocale "%F" "2011-07-11" > > main = putStrLn $ case now of > ? ? ? ? ? ? ? ? ? ?Nothing -> "Failed Parse" > ? ? ? ? ? ? ? ? ? ?Just x -> (formatTime defaultTimeLocale "%F" x) > > On Sat, Jul 9, 2011 at 12:33 PM, Rolf Hanson <rolf.han...@gmail.com> wrote: >> Hi, I'm trying to iterate over a range of dates and print them out. >> Here's how I am doing it in Ruby: >> >> 'require 'date' >> >> now ? ? ?= Date.parse('2011-07-11') >> end_date = Date.parse('2011-12-31') >> >> (now..end_date).each do |d| >> ?# print out a date that looks like: >> ?# Monday, July 11, 2011 >> ?puts "#{d.strftime('%A, %B %d, %Y')}" >> end >> >> I've been looking at the docs for Data.Time.Format and Data.Time.Calendar >> and am a bit puzzled at where to begin. Anyone have ideas? I've not found >> many (any?) examples of time and date manipulation in Haskell. >> >> RW >> _______________________________________________ >> Beginners mailing list >> Beginners@haskell.org >> http://www.haskell.org/mailman/listinfo/beginners >> > ------------------------------ Message: 4 Date: Sat, 9 Jul 2011 13:52:19 -0400 From: David McBride <dmcbr...@neondsl.com> Subject: [Haskell-beginners] Fwd: Can i define a record without defining access method. To: beginners@haskell.org Message-ID: <can+tr41ekfhw9etxg5yefg6cbxe6fyzcqe_wtdkf_ssh2l1...@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1 I've never used the main aeson library, but I just tried the aeson-qq library and got this without any real problem. ?Try this: {-# LANGUAGE QuasiQuotes, TemplateHaskell, DeriveDataTypeable #-} import Data.Text import Data.Aeson import Data.Aeson.QQ import Data.Aeson.Generic import Data.Aeson.Types myReq = [aesonQQ| {age: <|age|>, version: <|version|>} |] ?where age = 34 :: Integer ? ? ? ?version = "1.2" myResp = [aesonQQ| {age: <|name|>, version: <|version|>} |] ?where name = "harold" ? ? ? ?version = "1.3" >encode $ Data.Aeson.Generic.toJSON myReq Chunk "{\"age\":34,\"version\":\"1.2\"}" Empty >encode $ Data.Aeson.Generic.toJSON myResp Chunk "{\"age\":\"harold\",\"version\":\"1.3\"}" Empty On Sat, Jul 9, 2011 at 12:41 PM, yi huang <yi.codepla...@gmail.com> wrote: > On Sun, Jul 10, 2011 at 12:25 AM, Chadda? Fouch? <chaddai.fou...@gmail.com> > wrote: >> >> On Sat, Jul 9, 2011 at 5:59 PM, yi huang <yi.codepla...@gmail.com> wrote: >> > ?On Sat, Jul 9, 2011 at 6:45 PM, Tom Murphy <amin...@gmail.com> wrote: >> >> >> >> On 7/9/11, yi huang <yi.codepla...@gmail.com> wrote: >> >> > I'm trying to create a haskell implementation of json rpc, I try to >> >> > define >> >> > protocol using record like this: >> >> > >> >> > data Request = Request { >> >> > ? ? version :: Integer >> >> > ? , id ? ? ?:: Integer >> >> > ? , method ?:: String >> >> > ? , args ? ?:: [Value] >> >> > } deriving (Typeable, Data, Show) >> >> >> >> > so i can use json library to encode/decode it. >> >> > But this code fails, because haskell will define access function >> >> > automaticlly, and function names conflicts. >> >> > My question is, is there a way i can define record without access >> >> > function, >> >> > so i can have same attribute name in multiple record. >> >> >> >> If you really want to keep those attribute names exactly, you'll have >> to check where the conflict is and find a way not to import the >> conflicting function name. Here I guess "id" is the big problem since >> it comes with the prelude you'll have to use the NoImplicitPrelude >> extension and explicitly "import Prelude hiding (id)", I suggest you >> make a separate module for your type definition so you don't have to >> worry about that in the rest of your code. > > Sorry i don't describe my problem well, actually i have two records, Request > and Response, some attributes have same names, e.g. version, id. > data Request = Request { > ? ? version :: Int > ? ? ... > } > data Response = Response { > ? ? version :: Int > ? ? ... > } > And yes, i really want to keep those names exactly, so aeson can > automatically encode them to right json object. > If there are no way to hide access function, then i guess i have to define > them in seperate module, or define them as normal data constructor with > encode/decode precedure defined manually. Both is not?pleasant to me. >> >> -- >> Jeda? > > > > -- > http://www.yi-programmer.com/blog/ > > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://www.haskell.org/mailman/listinfo/beginners > > ------------------------------ Message: 5 Date: Sat, 9 Jul 2011 14:28:35 -0400 From: Brandon Allbery <allber...@gmail.com> Subject: Re: [Haskell-beginners] Can i define a record without defining access method. To: yi huang <yi.codepla...@gmail.com> Cc: beginners@haskell.org Message-ID: <cakfcl4x73xqncitmvj9oow-wb8qojv1tuhb5dvjvdbfpjq9...@mail.gmail.com> Content-Type: text/plain; charset=UTF-8 On Sat, Jul 9, 2011 at 12:41, yi huang <yi.codepla...@gmail.com> wrote: > On Sun, Jul 10, 2011 at 12:25 AM, Chadda? Fouch? <chaddai.fou...@gmail.com> > wrote: >> conflicting function name. Here I guess "id" is the big problem since >> it comes with the prelude you'll have to use the NoImplicitPrelude >> extension and explicitly "import Prelude hiding (id)", I suggest you If the first thing you do is "import Prelude ...", you shouldn't need the extension, IIRC? (Doesn't the Report spec that?) > Sorry i don't describe my problem well, actually i have two records, Request > and Response, some attributes have same names, e.g. version, id. If they always have the same types (that is, "version" isn't an Int in one and String in another) then the -XDisambiguateRecordFields extension will help. -- brandon s allbery ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?allber...@gmail.com wandering unix systems administrator (available) ? ? (412) 475-9364 vm/sms ------------------------------ _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners End of Beginners Digest, Vol 37, Issue 16 *****************************************