[Haskell-beginners] Type error in sub-function

Barbu Paul - Gheorghe barbu.paul.gheorghe at gmail.com
Wed Jul 23 12:29:53 UTC 2014


On 07/23/2014 03:08 PM, 양철웅 wrote:
> Hi, all!

Hi,

Code attached and online: http://lpaste.net/107954

If you look at the formatTime docs [1] you'll see that it returns a "String" not
an "IO String" as you expected in the original code, so we need to wrap that in
the IO monad using "return", because on the "utc" case branch you're in a monad
(keyword: "do").

After doing this modification we bound an IO String to timedVal in the where
clause, thus it's no longer necessary to "return timedVal" on the ('x': val)
branch of the first case since timedVal is already an IO monad containing a string.

Hope this helps.

PS: Also if I were you, I'd extract the barFunc function form the fooFunc
function and write it as a standalone with explicit types, too. For me, seeing
the types helps a lot.

http://hackage.haskell.org/package/time-1.4.2/docs/Data-Time-Format.html#v:formatTime

-- 
Barbu Paul - Gheorghe
Common sense is not so common - Voltaire
Visit My GitHub profile to see my open-source projects - https://github.com/paullik
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.hs
Type: text/x-haskell
Size: 760 bytes
Desc: not available
URL: <http://www.haskell.org/pipermail/beginners/attachments/20140723/e8c0ce4d/attachment.hs>


More information about the Beginners mailing list