[Haskell-cafe] expected vs inferred type confusion

Stephen Howard stephen at enterity.com
Mon Jun 23 11:16:10 EDT 2008


I am having issues with type signatures for the resourceHandler action 
below.  I haven't figured out what I'm doing wrong to cause the wrong 
type to be returned.  It looks like Haskell is inferring that I'm 
returning a function from this action, when from the type signature I've 
specified, that is not what I'm wanting.  The gist of the code is based 
on the request_method of the passed in HttpRequest, choose an action to 
run and pass it the needed parameters.

the error:

renao.hs:6:4:
    Couldn't match `HttpResponse' against `IO HttpResponse'
      Expected type: IO HttpResponse
      Inferred type: IO (IO HttpResponse)
    In the expression: return $ (handler session request)
    In the result of a 'do' expression: return $ (handler session request)

the code:

import HttpMessage
import HttpSession

resourceHandler :: HttpSession -> HttpRequest -> IO HttpResponse
resourceHandler session request = do
    return $ handler session request
    where
        handler = which_handler request
        which_handler r = case request_method r of
            Get    -> get_resources
            Head   -> last_modified
            Post   -> update_resources
            Put    -> create_resources
            Delete -> delete_resources


get_resources :: HttpSession -> HttpRequest -> IO HttpResponse
get_resources session request = undefined

-- ... the same stubbed definition for the other handlers 
(last_modified, etc)


More information about the Haskell-Cafe mailing list