[Haskell-cafe] newbie help

Abhijit Ray avizit at gmail.com
Fri Nov 4 02:38:16 EST 2005


Hi I just started on haskell , i am using the yet another haskell
tutorial by Hal Daume

I wrote the following program and it dint compile.
what's wrong with it

module Main
        where

import IO

main = do
        hSetBuffering stdin LineBuffering
        let testList = makeList
        let sum = foldr (+) 0 testList
        putStrLn "Sum is " ++ show(sum)

makeList = do
        putStrLn "enter a num"
        num <- getLine
        let nbr = read num
        if nbr == 0
                then do
                        return []
                else do
                        all <-  makeList
                        return  (nbr : all)
----------------------------------------------
the error i get is

Chasing modules from: Sum.hs
Compiling Main             ( Sum.hs, Sum.o )

Sum.hs:6:
    Couldn't match `[a]' against `IO ()'
        Expected type: [a]
        Inferred type: IO ()
    In the application `putStrLn "Sum is "'
    In the first argument of `(++)', namely `putStrLn "Sum is "'

Sum.hs:9:
    Couldn't match `[b]' against `IO [a]'
        Expected type: [b]
        Inferred type: IO [a]
    In the third argument of `foldr', namely `testList'
    In the definition of `sum': sum = foldr (+) 0 testList
-----------------------------

Thanks,
Abhijit Ray


More information about the Haskell-Cafe mailing list