> > Sorry I am being a pain, just trying to understand.
> > the error is:
> > Function main has the type [(Prelude.IO ())] instead of IO ().
> 
> Yes, main must return an IO action, not a list of them.
> 
> > printTable :: Foo -> [IO ()]
> > printTable []     = []
> > printTable (x:xs) = putStrLn x : printTable xs
> >
> > main :: [IO ()]
> > main =  do
> >            let tab1 = ...
> >            printTable tab1
> 
> If you want to convert a list of IO actions into a
> single action which executes each of these in turn, then
> you can use the `sequence' function:
> 
>         main :: IO ()
>         main =  do
>                    let tab1 = ...
>                    sequence (printTable tab1)

It's actually sequence_ in Haskell '98.

> However, it may make more sense to do the sequencing in
> the `printTable' function itself:
> 
>         printTable :: Foo -> IO ()
>         printTable []     = return ()
>         printTable (x:xs) = do { putStrLn x; printTable xs; }
> 
>         main :: IO ()
>         main =  do
>                    let tab1 = ...
>                    printTable tab1

It's even easier with mapM_, which obviates the need for printTable:

>         main :: IO ()
>         main =  do
>                    let tab1 = ...
>                    mapM_ putStrLn tab1

-Paul

Reply via email to