[Haskell-cafe] IO Monad operation madness

Rob Hoelz hoelz at wisc.edu
Thu May 17 18:25:52 EDT 2007


Hello again,

I'm still working on that binding, and I've come to a problem that I
just can't figure out.  I'm sure it's staring me right in the face, so
I think another pair of eyes to take a look.

So if you look at my previous message, I defined a linked list data
type in C.  I'm trying to convert it to a Haskell list of strings, so
here's my function:

linkedListToHaskellStringList :: LinkedList -> IO [String]
linkedListToHaskellStringList listPtr =
    let convertList' ptr =
        if listIsNull ptr
            then
                []
            else
                let str = peekCString =<< (linked_list_getdata ptr)
                next <- linked_list_next ptr
                str : (convertList' next)
    in
        sequence $ convertList' listPtr

listIsNull :: LinkedList -> Bool
listIsNull (LinkedList ptr) = ptr == nullPtr

So here's the compile error:

Option.hsc:63:14:
    Couldn't match expected type `[t]'
           against inferred type `IO LinkedList'
    In a 'do' expression: next <- linked_list_next ptr
    In the expression:
        if listIsNull ptr then
            []
        else
            do let str = peekCString =<< linked_list_getdata ptr
               next <- linked_list_next ptr
                 str : (convertList' next)
    In the definition of `convertList'':
        convertList' ptr
                       = if listIsNull ptr then
                             []
                         else
                             do let str = ...
                                next <- linked_list_next ptr
                                  str : (convertList' next)

Could anyone tell me what I'm doing wrong?  Thanks a lot!

-Rob


More information about the Haskell-Cafe mailing list