[Haskell-beginners] OI UTCTime to String

Arjun Comar nrujac at gmail.com
Thu Nov 10 19:07:09 UTC 2016


Adding to Francesco's reply, UTCTime is not a String either. Luckily, it
does have a Show instance however, which means you probably want something
like:

    getDateString = do
        date <- getCurrentTime
        return $ show date

Or, more simply: getDateString = fmap show getCurrentTime

You will still need to use bind, fmap, or do to get at the actual date
string however.

Thanks,
Arjun

On Thu, Nov 10, 2016 at 1:58 PM Francesco Ariis <fa-ml at ariis.it> wrote:

> On Thu, Nov 10, 2016 at 07:44:17PM +0100, sasa bogicevic wrote:
> > Hi All,
> >
> > This is a small program
> >
> > [...]
>
> Hey Sasa,
> If we put this into ghci
>
>     λ> :t formatDateString $ timeFromString _
>
> the "hole" tells us we need something of type String, but `getDateString`
> is not!
>
>     λ> :t getDateString
>     getDateString :: IO UTCTime
>
> That means you have to bind it inside a `do` block (or use >>=).
> Ask for more if I was not clear!
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20161110/59392610/attachment.html>


More information about the Beginners mailing list