Created
November 15, 2017 08:47
-
-
Save boj/8249f7786af8227b06a1a9713f56c7eb to your computer and use it in GitHub Desktop.
Show how to use Haskell type symbols in Servant APIs to generate string URLs
This file contains hidden or 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 -XOverloadedStrings -XDataKinds -XTypeOperators' -p 'ghc.withPackages (pkgs: [ pkgs.servant-server ])' | |
| module Main where | |
| import Data.List | |
| import Data.Proxy | |
| import GHC.TypeLits | |
| import Servant | |
| type ApiTerm = "api" | |
| type VersionTerm = "v1" | |
| type FooTerm = "foo" | |
| type BarTerm = "bar" | |
| type Api = ApiTerm :> VersionTerm :> ( | |
| FooTerm :> Get '[JSON] () | |
| :<|> BarTerm :> Get '[JSON] () | |
| ) | |
| main :: IO () | |
| main = do | |
| let a = symbolVal (Proxy :: Proxy ApiTerm) | |
| b = symbolVal (Proxy :: Proxy VersionTerm) | |
| c = symbolVal (Proxy :: Proxy FooTerm) | |
| f = "/" ++ intercalate "/" [a, b, c] | |
| print f |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment