Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Expected a type, but ‘Request’ has kind ‘* -> *’

Tags:

haskell

I wrote simple hello world server (http) and i have declared my request handler's type as,

type RequestHandler = Request -> IO Response

It throws error as,

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’

complete-code

This error message makes no sense to me..

Why is this error thrown and how can i fix this?


1 Answers

Request has data in the form of a generic type attached to it (the a in Request a and it represents the request-body) - this is meant when Haskell tells you that Request has kind * -> *

So you basically have to fix it - either 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 could say:

type RequestHandler = Request_String -> IO Response

too. Or you make your handler generic:

type RequestHandler a = Request a -> IO Response

of course with this you will have to change some of your other functions/definitions too (for example the helloWorldHandler).

like image 165
Random Dev Avatar answered Feb 20 '26 19:02

Random Dev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!