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:  searching for a file (Sean Perry)
   2. Re:  searching for a file (Michael Mossey)
   3. Re:  get date (SOLVED) (Luca Ciciriello)
   4.  Re: State monad question (Heinrich Apfelmus)
   5. Re:  get date (Luca Ciciriello)
   6. Re:  get date (Ozgur Akgun)
   7. Re:  get date (Luca Ciciriello)
   8.  Re: Integer by default. (Maciej Piechotka)
   9. Re:  get date (Ozgur Akgun)


----------------------------------------------------------------------

Message: 1
Date: Wed, 23 Jun 2010 22:05:04 -0700
From: Sean Perry <sha...@speakeasy.net>
Subject: Re: [Haskell-beginners] searching for a file
To: beginners <beginners@haskell.org>
Message-ID: <1277355904.3904.27.ca...@turion>
Content-Type: text/plain

On Wed, 2010-06-23 at 20:56 -0700, Michael Mossey wrote:
> Can I get a hint how to do this:
> 
> Given a directory D and a file extension E, find the newest file in D 
> among all files with extension E.
> 
> I wouldn't mind if you point me to the functions that are useful and 
> leave the rest as an exercise. Or even just point me to the module(s) 
> that is(are) useful.
> 

http://www.haskell.org/onlinelibrary/directory.html does not work for
you?




------------------------------

Message: 2
Date: Wed, 23 Jun 2010 22:41:42 -0700
From: Michael Mossey <m...@alumni.caltech.edu>
Subject: Re: [Haskell-beginners] searching for a file
To: beginners <beginners@haskell.org>
Message-ID: <4c22f016.6040...@alumni.caltech.edu>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed



Sean Perry wrote:
> On Wed, 2010-06-23 at 20:56 -0700, Michael Mossey wrote:
>> Given a directory D and a file extension E, find the newest file in D 
>> among all files with extension E.
> http://www.haskell.org/onlinelibrary/directory.html does not work for
> you?

That looks good. I'll see if I can get it to work.

Thanks,
Mike



------------------------------

Message: 3
Date: Thu, 24 Jun 2010 08:52:04 +0200
From: Luca Ciciriello <luca_cicirie...@hotmail.com>
Subject: Re: [Haskell-beginners] get date (SOLVED)
To: Felipe Lessa <felipe.le...@gmail.com>
Cc: beginners@haskell.org
Message-ID: <blu0-smtp602d8dff7fe74412886b69a...@phx.gbl>
Content-Type: text/plain; charset=us-ascii

Thanks Felipe.
Yes I use getCurrentTime. But I found I a stupid error in my code.
Now all works fine.
Thanks anyway for your answer.

Luca.


On Jun 23, 2010, at 8:13 PM, Felipe Lessa wrote:

> On Wed, Jun 23, 2010 at 08:03:16PM +0200, Luca Ciciriello wrote:
>> How can I get the current system date-time in Haskell?
>> 
>> I've used the library Time, but on MacOS X 10.6.4 the year is always 0.
>> 
>> Luca.
> 
> Do you mean, you used getCurrentTime from the time package[1]?
> What does the following line do?
> 
>  (toGregorian . utctDay) `fmap` getCurrentTime
> 
> On my system,
> 
>  GHCi, version 6.10.4: http://www.haskell.org/ghc/  :? for help
>  Loading package ghc-prim ... linking ... done.
>  Loading package integer ... linking ... done.
>  Loading package base ... linking ... done.
>  Prelude> :m Data.Time
>  Prelude Data.Time> (toGregorian . utctDay) `fmap` getCurrentTime
>  Loading package old-locale-1.0.0.1 ... linking ... done.
>  Loading package time-1.1.4 ... linking ... done.
>  (2010,6,23)
> 
> http://hackage.haskell.org/packages/archive/time/1.2.0.3/doc/html/Data-Time-Clock.html#v%3AgetCurrentTime
> 
> HTH,
> 
> --
> Felipe.
> 



------------------------------

Message: 4
Date: Thu, 24 Jun 2010 09:20:55 +0200
From: Heinrich Apfelmus <apfel...@quantentunnel.de>
Subject: [Haskell-beginners] Re: State monad question
To: beginners@haskell.org
Message-ID: <hvv10n$3o...@dough.gmane.org>
Content-Type: text/plain; charset=UTF-8; format=flowed

Jordan Cooper wrote:
> Secondly, as to why I wanted to use a monad here, importantFunction
> (which is called playerTurn in the real program) would contain a
> series of functions that would modify Cards and Players, not just one
> each as in my initial example. Thus it seems like I'd have to end up
> with let foo... let foo'... etc. which, from my reading in RWH, seems
> to be an acceptable use for a State monad.

While your use of the state monad may well be sensible, keep in mind 
that many cases of "threading state" are covered by ordinary functional 
programming idioms, like function composition

     process = take 3 . sort . map length . filter (not . null) . lines

and accumulating parameters

     average xs = foldl' step (0,0) xs
         where
         step (!s,!n) x = (s+x, n+1)

     reverse xs = go xs
         where
         go ys []     = ys
         go ys (x:xs) = go (x:ys) xs

The functions in  Data.Map  are a good example as well: most of them 
"change" the map, but a state monad would be overkill for that.


The state monad is mainly beneficial when you otherwise would have many 
functions of type

     :: s -> (a,s)

with ugly plumbing like

     let (a,s') = foo s; (b,s'') = foo s' in ..


Regards,
Heinrich Apfelmus

--
http://apfelmus.nfshost.com



------------------------------

Message: 5
Date: Thu, 24 Jun 2010 09:52:46 +0200
From: Luca Ciciriello <luca_cicirie...@hotmail.com>
Subject: Re: [Haskell-beginners] get date
To: Felipe Lessa <felipe.le...@gmail.com>
Cc: beginners@haskell.org
Message-ID: <blu0-smtp712bfba5fd6756c27b01b19a...@phx.gbl>
Content-Type: text/plain; charset=us-ascii

Just a question.
How can I obtain a String from

currentTime :: IO Day
currentTime =  utctDay `fmap` getCurrentTime

Here currentTime returns to me 2010-06-24, but I want "2010-06-24".
In another worlds I need a function 

currentTimeStr :: IO Day -> String

Any Idea?

Luca.



On Jun 23, 2010, at 8:13 PM, Felipe Lessa wrote:

> On Wed, Jun 23, 2010 at 08:03:16PM +0200, Luca Ciciriello wrote:
>> How can I get the current system date-time in Haskell?
>> 
>> I've used the library Time, but on MacOS X 10.6.4 the year is always 0.
>> 
>> Luca.
> 
> Do you mean, you used getCurrentTime from the time package[1]?
> What does the following line do?
> 
>  (toGregorian . utctDay) `fmap` getCurrentTime
> 
> On my system,
> 
>  GHCi, version 6.10.4: http://www.haskell.org/ghc/  :? for help
>  Loading package ghc-prim ... linking ... done.
>  Loading package integer ... linking ... done.
>  Loading package base ... linking ... done.
>  Prelude> :m Data.Time
>  Prelude Data.Time> (toGregorian . utctDay) `fmap` getCurrentTime
>  Loading package old-locale-1.0.0.1 ... linking ... done.
>  Loading package time-1.1.4 ... linking ... done.
>  (2010,6,23)
> 
> http://hackage.haskell.org/packages/archive/time/1.2.0.3/doc/html/Data-Time-Clock.html#v%3AgetCurrentTime
> 
> HTH,
> 
> --
> Felipe.
> 



------------------------------

Message: 6
Date: Thu, 24 Jun 2010 10:59:33 +0300
From: Ozgur Akgun <ozgurak...@gmail.com>
Subject: Re: [Haskell-beginners] get date
To: Luca Ciciriello <luca_cicirie...@hotmail.com>
Cc: beginners@haskell.org
Message-ID:
        <aanlktinsshdgvav2hlahgf497fbygv99xsta5b8hl...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

On 24 June 2010 10:52, Luca Ciciriello <luca_cicirie...@hotmail.com> wrote:

> Just a question.
> How can I obtain a String from
>
> currentTime :: IO Day
> currentTime =  utctDay `fmap` getCurrentTime
>
> Here currentTime returns to me 2010-06-24, but I want "2010-06-24".
> In another worlds I need a function
>
>
I bet Day has a Show instance (that's why you get 2010-06-24 in ghci I
suppose)
Just use that.



> currentTimeStr :: IO Day -> String
>
>
Getting out of IO? I would think again. Following might be what you really
want:

currentTimeStr :: IO Day -> IO String



> Any Idea?
>
> Luca.
>

Best,
Ozgur
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
http://www.haskell.org/pipermail/beginners/attachments/20100624/94948a5f/attachment-0001.html

------------------------------

Message: 7
Date: Thu, 24 Jun 2010 10:17:32 +0200
From: Luca Ciciriello <luca_cicirie...@hotmail.com>
Subject: Re: [Haskell-beginners] get date
To: Ozgur Akgun <ozgurak...@gmail.com>
Cc: beginners@haskell.org
Message-ID: <blu0-smtp557a31c88bb9f6cf0a19329a...@phx.gbl>
Content-Type: text/plain; charset="us-ascii"

Starting from the beginning, my original problem is to create the string:

"File creation date:  " ++ currentSystemDate ++ " by MyCompany"

to obtain the string

"File creation date: 2010-06-24 by MyCompany"

Probably this is really trivial, but I'm a real beginner in Haskell and this 
seems to me a big problem.

Luca.

On Jun 24, 2010, at 9:59 AM, Ozgur Akgun wrote:

> On 24 June 2010 10:52, Luca Ciciriello <luca_cicirie...@hotmail.com> wrote:
> Just a question.
> How can I obtain a String from
> 
> currentTime :: IO Day
> currentTime =  utctDay `fmap` getCurrentTime
> 
> Here currentTime returns to me 2010-06-24, but I want "2010-06-24".
> In another worlds I need a function
> 
> 
> I bet Day has a Show instance (that's why you get 2010-06-24 in ghci I 
> suppose)
> Just use that.
> 
>  
> currentTimeStr :: IO Day -> String
> 
> 
> Getting out of IO? I would think again. Following might be what you really 
> want:
> 
> currentTimeStr :: IO Day -> IO String
> 
>  
> Any Idea?
> 
> Luca.
>  
> Best,
> Ozgur 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
http://www.haskell.org/pipermail/beginners/attachments/20100624/02301868/attachment-0001.html

------------------------------

Message: 8
Date: Thu, 24 Jun 2010 09:54:49 +0100
From: Maciej Piechotka <uzytkown...@gmail.com>
Subject: [Haskell-beginners] Re: Integer by default.
To: beginners@haskell.org
Message-ID: <1277369688.13353.17.ca...@localhost.localdomain>
Content-Type: text/plain; charset="utf-8"

On Wed, 2010-06-23 at 11:51 -0300, Felipe Lessa wrote:
> On Wed, Jun 23, 2010 at 09:38:24PM +0800, Lyndon Maydwell wrote:
> > Is there a way to get the prelude functions to use Integer by default
> > rather than Int?
> 
> In general, I think it is cleaner to use explicit type signatures
> instead of defaulting.  Running GHC with -Wall will warn you
> whenever you default to something.
> 
> Cheers,
> 
> --
> Felipe.

Also it helps a lot tracking type errors (and other errors are nearly
non-existing in Haskell ;) ).

Regards
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part
Url : 
http://www.haskell.org/pipermail/beginners/attachments/20100624/7ce21d23/attachment-0001.bin

------------------------------

Message: 9
Date: Thu, 24 Jun 2010 12:16:57 +0300
From: Ozgur Akgun <ozgurak...@gmail.com>
Subject: Re: [Haskell-beginners] get date
To: Luca Ciciriello <luca_cicirie...@hotmail.com>
Cc: beginners@haskell.org
Message-ID:
        <aanlktikm8pd0g7ekobyec2a75kmqhsdnmxrca_q63...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Then you might want to use something like:

currentTimeStr :: IO String
currentTimeStr = do ct <- currentTime
                    return ("File creation date: " ++ show ct ++ " by
MyCompany")

Or more concisely,

currentTimeStr :: IO String
currentTimeStr = liftM (\ ct -> "File creation date: " ++ show ct ++ " by
MyCompany" ) currentTime

My point is, the type of currentTimeStr is IO String, not just String.
Because you are working on an IO value.

Best,

PS: If you are not confident with the piece of code I've suggested, please
have a look at the io/monads/do-notation sections of the Real World Haskell.


On 24 June 2010 11:17, Luca Ciciriello <luca_cicirie...@hotmail.com> wrote:

> Starting from the beginning, my original problem is to create the string:
>
> "File creation date:  " ++ currentSystemDate ++ " by MyCompany"
>
> to obtain the string
>
> "File creation date: 2010-06-24 by MyCompany"
>
> Probably this is really trivial, but I'm a real beginner in Haskell and
> this seems to me a big problem.
>
> Luca.
>
> On Jun 24, 2010, at 9:59 AM, Ozgur Akgun wrote:
>
> On 24 June 2010 10:52, Luca Ciciriello <luca_cicirie...@hotmail.com>wrote:
>
>> Just a question.
>> How can I obtain a String from
>>
>> currentTime :: IO Day
>> currentTime =  utctDay `fmap` getCurrentTime
>>
>> Here currentTime returns to me 2010-06-24, but I want "2010-06-24".
>> In another worlds I need a function
>>
>>
> I bet Day has a Show instance (that's why you get 2010-06-24 in ghci I
> suppose)
> Just use that.
>
>
>
>> currentTimeStr :: IO Day -> String
>>
>>
> Getting out of IO? I would think again. Following might be what you really
> want:
>
> currentTimeStr :: IO Day -> IO String
>
>
>
>> Any Idea?
>>
>> Luca.
>>
>
> Best,
> Ozgur
>
>
>


-- 
Ozgur Akgun
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
http://www.haskell.org/pipermail/beginners/attachments/20100624/b70b09cb/attachment.html

------------------------------

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 24, Issue 32
*****************************************

Reply via email to