[Haskell-cafe] Noob question and sequence of operations (print then do something else)

John Wicket galtor003 at gmail.com
Mon Sep 24 01:40:46 EDT 2007


Sorry, I was actually trying to use this as an example for something more
complicated I am trying to do.  In this example, why would the inferred type
be "IO ()"

aa :: String -> String
aa instr = do
  putStrLn "abc"
  putStrLn "abc"
  return "Az"

  Couldn't match expected type `[t]' against inferred type `IO ()'
    In the expression: putStrLn "abc"
    In a 'do' expression: putStrLn "abc"
    In the expression:
    do putStrLn "abc"
       putStrLn "abc"
       return "Az"

On 9/24/07, Sam Hughes <hughes at rpi.edu> wrote:
>
> John Wicket wrote:
> > I am still in an imperative way of thinking.  In this example here; how
> > would I call "putStrLn" and then set the function with a value.  Eg:
> >
> > aa :: String -> IO ()
> > aa instr = do
> >   putStrLn "abc"
> >   putStrLn "abc"
> >   return "123"
> >
> > --- The error I am getting.
> >
> >     Couldn't match expected type `()' against inferred type `[Char]'
> >     In the first argument of `return', namely `"123"'
> >     In the expression: return "123"
> >     In the expression:
> >     do putStrLn "abc"
> >        putStrLn "abc"
> >        return "123"
>
> Your type signature is wrong.  If you want an IO action whose return
> value is a String, say so:
>
> aa :: String -> IO String
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20070924/bc8198ca/attachment-0001.htm


More information about the Haskell-Cafe mailing list