Skip to content

Instantly share code, notes, and snippets.

@RobertFischer
Created March 28, 2017 17:27
Show Gist options
  • Save RobertFischer/2218c6b74451b5529189420a9c603722 to your computer and use it in GitHub Desktop.
Save RobertFischer/2218c6b74451b5529189420a9c603722 to your computer and use it in GitHub Desktop.
What's wrong with this?
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeOperators #-}
module Lib
( startApp
, app
) where
import Data.Aeson
import Data.Aeson.TH
import Network.Wai
import Network.Wai.Handler.Warp
import Servant
data User = User
{ userId :: Int
, userFirstName :: String
, userLastName :: String
} deriving (Eq, Show)
$(deriveJSON defaultOptions ''User)
type API = "users" :> Capture "id" Integer :> Get '[JSON] [User]
startApp :: IO ()
startApp = run 8080 app
app :: Application
app = serve api server
api :: Proxy API
api = Proxy
server :: Server API
server = return users
users :: Integer -> Handler [User]
users id = return $ [ User 1 "Isaac" "Newton", User 2 "Albert" "Einstein" ]
@RobertFischer
Copy link
Author

    • Couldn't match type ‘Integer -> Handler [User]’
                     with ‘transformers-0.5.2.0:Control.Monad.Trans.Except.ExceptT
                             ServantErr IO [User]’
      Expected type: Server API
        Actual type: Integer -> Integer -> Handler [User]
    • Possible cause: ‘return’ is applied to too many arguments
      In the expression: return users
      In an equation for ‘server’: server = return users

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment