Skip to content

Instantly share code, notes, and snippets.

@jml
Last active October 10, 2015 16:20
Show Gist options
  • Select an option

  • Save jml/41c25a1c668bef34e0c1 to your computer and use it in GitHub Desktop.

Select an option

Save jml/41c25a1c668bef34e0c1 to your computer and use it in GitHub Desktop.
lib/Hazard/UserAPI.hs:65:18:
Couldn't match expected type ‘b0 :~> EitherT ServantErr IO’
with actual type ‘(forall a. m0 a -> n0 a) -> m0 :~> n0’
Probable cause: ‘Nat’ is applied to too few arguments
In the first argument of ‘(.)’, namely ‘Nat’
In the expression: Nat . readerToEither'
lib/Hazard/UserAPI.hs:65:24:
Couldn't match expected type ‘Reader String :~> b0’
with actual type ‘Reader String a0 -> EitherT ServantErr IO a0’
Probable cause: ‘readerToEither'’ is applied to too few arguments
In the second argument of ‘(.)’, namely ‘readerToEither'’
In the expression: Nat . readerToEither'
-- Copyright (c) 2015 Jonathan M. Lange <jml@mumak.net>
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeOperators #-}
module Hazard.UserAPI (userAPI, server) where
import BasicPrelude
import Control.Monad.Reader
import Control.Monad.Trans.Either
import Servant
import Servant.HTML.Blaze (HTML)
import Hazard.Users (UserCreationRequest, User, UserID)
type UserAPI = "users" :> Get '[JSON, HTML] [(UserID, Text)]
:<|> "users" :> ReqBody '[JSON] UserCreationRequest :> Post '[JSON] User
:<|> "user" :> Capture "userID" UserID :> Get '[JSON, HTML] User
userAPI :: Proxy UserAPI
userAPI = Proxy
serverT :: ServerT UserAPI (Reader String)
serverT = allUsers :<|> addUser :<|> oneUser
server :: Server UserAPI
server = enter readerToEither serverT
allUsers :: m [(UserID, Text)]
allUsers = undefined
addUser :: UserCreationRequest -> m User
addUser = undefined
oneUser :: UserID -> m User
oneUser = undefined
readerToEither :: Reader String :~> EitherT ServantErr IO
readerToEither = Nat . readerToEither'
readerToEither' :: forall a. Reader String a -> EitherT ServantErr IO a
readerToEither' r = return (runReader r "hi")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment