1 {-# LANGUAGE DataKinds #-}
2 {-# LANGUAGE MultiParamTypeClasses #-}
3 {-# LANGUAGE NoMonomorphismRestriction #-}
4 {-# LANGUAGE OverloadedStrings #-}
5 {-# LANGUAGE TypeApplications #-}
6 {-# LANGUAGE TypeFamilies #-}
7 {-# OPTIONS_GHC -fno-warn-orphans #-}
8 {-# OPTIONS_GHC -Wno-missing-signatures #-}
10 import Text.Read (readMaybe)
11 import qualified Pipes as P
12 import qualified Data.Text.Lazy as TL
13 import qualified Data.Text.Lazy.Encoding as TL
17 -- | Define the API, common to the client and server.
18 -- Either use @NoMonomorphismRestriction@ like here,
19 -- or add an argument to 'api',
20 -- to let the compiler infer its (complex) type.
21 -- Read the executables of the client and of the server
22 -- to see how to derive code from this 'api'.
24 "succ" </> capture @Integer "n"
25 <.> get @Integer @'[PlainText]
28 "countdown" </> capture @Integer "n"
29 <.> getStream @(P.Producer Integer IO ())
33 instance MimeEncodable Integer PlainText where
34 mimeEncode _ = TL.encodeUtf8 . TL.pack . show
35 instance MimeDecodable Integer PlainText where
37 let s = TL.unpack $ TL.decodeUtf8 bs in
39 Nothing -> Left $ "cannot parse as Integer: "<>s