[Haskell-beginners] Type error in sub-function

Gesh gesh at gesh.uni.cx
Wed Jul 23 12:30:50 UTC 2014


On 7/23/2014 3:08 PM, 양철웅 wrote:
Look at the error:
 > 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 }
Rewriting that do-block a little, we get:
 > do utcTime <- currentUTCTime
 >    problem
 >  where problem = formatTime defaultTimeLocale "%a" utcTime

In plain English, GHC's error message means:
 > On line 21 of test.hs, column 57:
 >      I (GHC) inferred from the context surrounding it that
 >      'problem' should have the type 'IO a' for some a.
 >      However, you defined 'problem' in a way that makes its
 >      type be 'String'. Therefore, I can't accept your program.

Do you see what caused the error?
How would you fix it?
HTH,
Gesh


More information about the Beginners mailing list