Deep confusion about monads

Ashley Yakeley ashley@semantic.org
Thu, 16 Aug 2001 16:30:57 -0700


At 2001-08-16 13:30, Mark Carroll wrote:

>in ghci,
>
>let x = readFile "/tmp/foo"

x here has type "IO String"

>putStr x

putStr wants x to be type "String". You want this:

do
  {
  x <- readFile "/tmp/foo";
  putStr x;
  }

...which is translated to...

readFile "/tmp/foo" >>= (\x -> putStr x)

>(>>=) :: IO a -> (a -> IO b) -> IO b

This one is correct.

-- 
Ashley Yakeley, Seattle WA