servant/servant-server/test/Servant/HoistSpec.hs

48 lines
1.3 KiB
Haskell
Raw Normal View History

{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
2017-10-01 18:20:09 +02:00
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE TypeSynonymInstances #-}
2017-10-01 18:20:09 +02:00
module Servant.HoistSpec where
import Data.Aeson
(ToJSON, encode)
2018-06-29 21:08:26 +02:00
import Test.Hspec
(Spec)
2017-10-01 18:20:09 +02:00
2018-06-29 21:08:26 +02:00
import Servant
2017-10-01 18:20:09 +02:00
-------------------------------------------------------------------------------
-- https://github.com/haskell-servant/servant/issues/734
-------------------------------------------------------------------------------
-- This didn't fail if executed in GHCi; cannot have as a doctest.
newtype App a = App a
type API = Get '[JSON] Int
:<|> ReqBody '[JSON] String :> Get '[JSON] Bool
api :: Proxy API
api = Proxy
server :: App Int :<|> (String -> App Bool)
server = undefined
-- Natural transformation still seems to need an explicit type.
f :: App a -> App a
f = id
server' :: App Int :<|> (String -> App Bool)
server' = hoistServer api f server
instance ToJSON a => MimeRender JSON a where mimeRender _ = encode
2017-10-01 18:20:09 +02:00
-------------------------------------------------------------------------------
-- Spec
-------------------------------------------------------------------------------
spec :: Spec
spec = return ()