Expected type, but "Request is of the form" * & # 8594; *
I wrote a simple hello world (http) server and I declared my request handler type as,
type RequestHandler = Request -> IO Response
It gives an error like,
simpleserver.hs:11:23:
Expecting one more argument to ‘Request’
Expected a type, but ‘Request’ has kind ‘* -> *’
In the type ‘Request -> IO Response’
In the type declaration for ‘RequestHandler’
This error message doesn't make any sense to me.
Why is this error occurring and how can I fix it?
source to share
Request
contains data as a generic type attached to it ( a
in Request a
and represents the request body) - this means that Haskell tells you what Request
is of the form * -> *
So, you basically need to fix this - or think of a fixed type and add it:
type RequestHandler = Request String -> IO Response
there are already types for this (for example Request_String
, so you can say:
type RequestHandler = Request_String -> IO Response
also. Or you make your handler generic:
type RequestHandler a = Request a -> IO Response
of course you will have to change some of your other functions / definitions (for example helloWorldHandler
).
source to share
Look at the type Request
: it needs one type parameter, which it uses to determine what to do with the body of the http request. This is what the error message tells you: haskell was expecting one argument Request
, and you gave it zero.
source to share