[Haskell-beginners] get date

Ozgur Akgun ozgurakgun at gmail.com
Thu Jun 24 05:16:57 EDT 2010


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_ciciriello at 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_ciciriello at 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-0001.html


More information about the Beginners mailing list