Last active
April 22, 2018 19:41
-
-
Save domenkozar/581b82912cb4f12d687aac6309c92ba1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
servant-sub-client.hs:63:22: error: | |
• Couldn't match type ‘(HomeC :<|> HomePostC) | |
:<|> (BetC :<|> Bet2C)’ | |
with ‘ClientM Text’ | |
Expected type: HomeC | |
Actual type: (HomeC :<|> HomePostC) :<|> (BetC :<|> Bet2C) | |
• In the first argument of ‘runClientM’, namely ‘(bC 3 :: HomeC)’ | |
In a stmt of a 'do' block: res <- runClientM (bC 3 :: HomeC) env | |
In the expression: | |
do manager <- newManager defaultManagerSettings | |
let env = mkClientEnv manager $ BaseUrl Http "localhost" 8090 "" | |
res <- runClientM (bC 3 :: HomeC) env | |
print res | |
| | |
63 | res <- runClientM (bC 3 :: HomeC) env | |
| ^^^^ | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env nix-shell | |
#!nix-shell -i runghc -p "haskellPackages.ghcWithPackages (pkgs: with pkgs; [servant-generic servant-client])" | |
#!nix-shell -I nixpkgs=http://nixos.org/channels/nixpkgs-unstable/nixexprs.tar.xz | |
{-# LANGUAGE DataKinds #-} | |
{-# LANGUAGE DeriveGeneric #-} | |
{-# LANGUAGE TypeFamilies #-} | |
{-# LANGUAGE TypeOperators #-} | |
{-# LANGUAGE KindSignatures #-} | |
{-# LANGUAGE PartialTypeSignatures #-} | |
{-# LANGUAGE PolyKinds #-} | |
{-# LANGUAGE UndecidableInstances #-} | |
{-# LANGUAGE OverloadedStrings #-} | |
import Data.Aeson.Types | |
import Data.Text | |
import GHC.Generics | |
import Servant | |
import Servant.API | |
import Servant.Client | |
import Servant.Generic | |
import Network.HTTP.Client (newManager, defaultManagerSettings) | |
data Site route = Site | |
{ about :: route :- | |
Capture "x" Text :> Get '[JSON] Text | |
, faq :: route :- | |
Capture "y" Int :> ToServant (SubSite AsApi) | |
} deriving Generic | |
data SubSite route = SubSite | |
{ home :: route :- | |
Get '[JSON] Text | |
, homePost :: route :- | |
Post '[JSON] Text | |
, bet :: route :- | |
Capture "z" Text :> | |
"asd" :> Get '[JSON] Text | |
, bet2 :: route :- | |
Capture "z" Text :> | |
"asd2" :> Get '[JSON] Int | |
} deriving Generic | |
type SiteAPI = ToServant (Site AsApi) | |
siteAPI :: Proxy SiteAPI | |
siteAPI = Proxy | |
type HomeC = ClientM Text | |
type HomePostC = ClientM Text | |
type BetC = Text -> ClientM Text | |
type Bet2C = Text -> ClientM Int | |
bC :: Int -> (HomeC :<|> HomePostC) :<|> BetC :<|> Bet2C | |
_ :<|> bC = client siteAPI | |
main :: IO () | |
main = do | |
manager <- newManager defaultManagerSettings | |
let env = mkClientEnv manager $ BaseUrl Http "localhost" 8090 "" | |
res <- runClientM (bC 3 :: HomeC) env | |
print res |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment