Haskell: I/O and Returning From a Function

In most functional languages, this would work. However, Haskell is a pure functional language. You are not allowed to do IO in functions, so the function can either be

  1. [Int] -> [Int] without performing any IO or
  2. [Int] -> IO [Int] with IO

The type of dot as inferred by the compiler is dot :: (Show t) => [t] -> IO [t] but you can declare it to be [Int] -> IO [Int]:

dot :: [Int] -> IO [Int]

See IO monad: http://book.realworldhaskell.org/read/io.html


I haven’t mentioned System.IO.Unsafe.unsafePerformIO that should be used with great care and with a firm understanding of its consequences.

Leave a Comment