
Hi All, This is a small program {-# LANGUAGE OverloadedStrings #-} module Main where import Control.Monad.IO.Class (liftIO) import qualified Data.ByteString.Lazy.Char8 as L import Data.Time import Network (withSocketsDo) import Network.HTTP.Conduit createRequestData today = [("index:brKursneListe",""), ("index:year","2016"), ("index:inputCalendar1", today), ("index:vrsta","3"), ("index:prikaz","0"), ("index:buttonShow","Prikazi")] timeFromString s = parseTimeOrError True defaultTimeLocale "%d %b %Y %l:%M %p" s formatDateString time = formatTime defaultTimeLocale "%m/%d/%Y" time getDateString = getCurrentTime getFormatedDate = formatDateString $ timeFromString getDateString main = do print $ getFormatedDate And here is my error main.hs:25:54: error: • Couldn't match type ‘IO UTCTime’ with ‘[Char]’ Expected type: String Actual type: IO UTCTime • In the first argument of ‘timeFromString’, namely ‘getDateString’ In the second argument of ‘($)’, namely ‘timeFromString getDateString’ In the expression: formatDateString $ timeFromString getDateString Thanks!

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!

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
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@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

It looks like you are trying to get time in UTC, then figuring out what
date it is? You should be able to get the answer you are looking for with
getFormattedDate = do
utc <- getCurrentTime
return $ formatTime defaultTimeLocale "%m/%d/%Y" utc
Just keep in mind that that is the date in UTC. Not in your local time
zone and it ignores daylight savings time. To get it in your time you'll
have to replace getCurrentTime with getZonedTime.
On Thu, Nov 10, 2016 at 1:44 PM, sasa bogicevic
Hi All,
This is a small program
{-# LANGUAGE OverloadedStrings #-} module Main where
import Control.Monad.IO.Class (liftIO) import qualified Data.ByteString.Lazy.Char8 as L import Data.Time import Network (withSocketsDo) import Network.HTTP.Conduit
createRequestData today = [("index:brKursneListe",""), ("index:year","2016"), ("index:inputCalendar1", today), ("index:vrsta","3"), ("index:prikaz","0"), ("index:buttonShow","Prikazi")]
timeFromString s = parseTimeOrError True defaultTimeLocale "%d %b %Y %l:%M %p" s
formatDateString time = formatTime defaultTimeLocale "%m/%d/%Y" time
getDateString = getCurrentTime
getFormatedDate = formatDateString $ timeFromString getDateString
main = do print $ getFormatedDate
And here is my error
main.hs:25:54: error: • Couldn't match type ‘IO UTCTime’ with ‘[Char]’ Expected type: String Actual type: IO UTCTime • In the first argument of ‘timeFromString’, namely ‘getDateString’ In the second argument of ‘($)’, namely ‘timeFromString getDateString’ In the expression: formatDateString $ timeFromString getDateString
Thanks!
_______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

Thanks guys! Didn't expect this much help so fast, great community! I think my main problem was that I was constantly trying to print the result for my formatted date string which was of type IO String (at some point) I just learned that to print IO you need to bind it something like this main = getFormattedDate >>= putStrLn Thanks a lot, You rock!
On Nov 10, 2016, at 20:23, David McBride
wrote: It looks like you are trying to get time in UTC, then figuring out what date it is? You should be able to get the answer you are looking for with
getFormattedDate = do utc <- getCurrentTime return $ formatTime defaultTimeLocale "%m/%d/%Y" utc
Just keep in mind that that is the date in UTC. Not in your local time zone and it ignores daylight savings time. To get it in your time you'll have to replace getCurrentTime with getZonedTime.
On Thu, Nov 10, 2016 at 1:44 PM, sasa bogicevic
wrote: Hi All, This is a small program
{-# LANGUAGE OverloadedStrings #-} module Main where
import Control.Monad.IO.Class (liftIO) import qualified Data.ByteString.Lazy.Char8 as L import Data.Time import Network (withSocketsDo) import Network.HTTP.Conduit
createRequestData today = [("index:brKursneListe",""), ("index:year","2016"), ("index:inputCalendar1", today), ("index:vrsta","3"), ("index:prikaz","0"), ("index:buttonShow","Prikazi")]
timeFromString s = parseTimeOrError True defaultTimeLocale "%d %b %Y %l:%M %p" s
formatDateString time = formatTime defaultTimeLocale "%m/%d/%Y" time
getDateString = getCurrentTime
getFormatedDate = formatDateString $ timeFromString getDateString
main = do print $ getFormatedDate
And here is my error
main.hs:25:54: error: • Couldn't match type ‘IO UTCTime’ with ‘[Char]’ Expected type: String Actual type: IO UTCTime • In the first argument of ‘timeFromString’, namely ‘getDateString’ In the second argument of ‘($)’, namely ‘timeFromString getDateString’ In the expression: formatDateString $ timeFromString getDateString
Thanks!
_______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
_______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
participants (4)
-
Arjun Comar
-
David McBride
-
Francesco Ariis
-
sasa bogicevic