[Haskell-beginners] Type error in sub-function
양철웅
cwyang at aranetworks.com
Wed Jul 23 12:08:49 UTC 2014
Hi, all!
When I compile my program below, ghc emits Type error.
Since the return type of foo Func is IO String and
first case statement has "return timedVal",
I think that ghc expects the type of timedVal as String.
However, the error message shows that
ghc expects timedVal should have type IO b0.
What am I missing?
Any comments are appreciated.
Thanks in advance!
Chul-Woong
--
import Data.Time.LocalTime (getZonedTime, zonedTimeToUTC)
import System.Locale (defaultTimeLocale)
import Data.Time.Format (formatTime)
import Data.Time.Clock (UTCTime)
currentUTCTime :: IO UTCTime
currentUTCTime = do
zTime <- getZonedTime
return (zonedTimeToUTC zTime)
fooFunc :: IO String
fooFunc = do
putStrLn "Hello, world"
barFunc "xutc"
where barFunc s =
case s of
"apple" -> return s
('x': val) -> return timedVal
where timedVal = case val of
"utc" -> do utcTime <-
currentUTCTime
formatTime
defaultTimeLocale "%a" utcTime
---
Prelude> :l test
[1 of 1] Compiling Main ( test.hs, interpreted )
test.hs:21:57:
Couldn't match expected type `IO b0' with actual type `String'
In the return type of a call of `formatTime'
In a stmt of a 'do' block:
formatTime defaultTimeLocale "%a" utcTime
In the expression:
do { utcTime <- currentUTCTime;
formatTime defaultTimeLocale "%a" utcTime }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20140723/a5ff12d3/attachment.html>
More information about the Beginners
mailing list