[Haskell-beginners] function not working as expected, type issues

Nadir Sampaoli nadirsampaoli at gmail.com
Wed Apr 9 06:20:58 UTC 2014


Hello Alexej
Il 09/apr/2014 08:03 "Alexej Magura" <sickhadas at gmail.com> ha scritto:
>
> K, so I have a function that I’m writing that takes a *string* and a
*count* and prints the *string* to STDOUT *count* times:
>
> displayD :: IO () -> String -> Int
> displayD string count = do
>         (count > 0) && hPutStr stdout string
>         (count > 0) && displayD string (count - 1)
>

At glance at least one of your errors comes from your type signature being
incorrect. Your function should takes first a String then an Int and should
return an IO () because you're printing stuff. So:

    displayD :: IO () -> String -> Int

should become:

    displayD :: String -> Int -> IO ()

Regards,
Nadir
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20140409/094f8b86/attachment.html>


More information about the Beginners mailing list