slides.tex 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. \documentclass[12pt]{beamer}
  2. \usetheme{metropolis}
  3. \usepackage{minted}
  4. \newenvironment{code}{\ttfamily}{\par}
  5. \title{servant}
  6. \subtitle{Defining web APIs at the type-level}
  7. \begin{document}
  8. \metroset{titleformat frame=smallcaps}
  9. \setminted{fontsize=\scriptsize}
  10. \maketitle
  11. \section{Introduction}
  12. \begin{frame}{Type-level DSLs?}
  13. \begin{itemize}
  14. \item (Uninhabited) types with attached ``meaning''
  15. \item The Expression Problem (Wadler 1998)
  16. \item API representation and interpretation are separated
  17. \item APIs become first-class citizens
  18. \end{itemize}
  19. \end{frame}
  20. \begin{frame}{Haskell extensions}
  21. \begin{itemize}
  22. \item TypeOperators
  23. \item DataKinds
  24. \item TypeFamilies
  25. \end{itemize}
  26. \end{frame}
  27. \begin{frame}[fragile]{A servant example}
  28. \begin{minted}{haskell}
  29. type PubAPI = "pubs" :> Get ’[JSON] [Pub]
  30. :<|> "pubs" :> "tagged"
  31. :> Capture "tag" Text
  32. :> Get ’[JSON] [Pub]
  33. \end{minted}
  34. \end{frame}
  35. \begin{frame}[fragile]{Computed types}
  36. \begin{minted}{haskell}
  37. type TaggedPubs = "tagged" :> Capture "tag" Text :> ...
  38. taggedPubsHandler :: Server TaggedPubs
  39. taggedPubsHandler tag = ...
  40. \end{minted}
  41. \end{frame}
  42. \begin{frame}[fragile]{Computed types}
  43. \begin{minted}{haskell}
  44. type TaggedPubs = "tagged" :> Capture "tag" Text :> ...
  45. taggedPubsHandler :: Server TaggedPubs
  46. taggedPubsHandler tag = ...
  47. Server TaggedPubs ~
  48. Text -> EitherT ServantErr IO [Pub]
  49. \end{minted}
  50. \end{frame}
  51. \section{Interpretations}
  52. \begin{frame}{servant-server}
  53. The one everyone is interested in!
  54. \begin{itemize}
  55. \item Based on WAI, can run on warp
  56. \item Interprets combinators with a simple \texttt{HasServer c} class
  57. \item Easy to use!
  58. \end{itemize}
  59. \end{frame}
  60. \begin{frame}[fragile]{HasServer ...}
  61. \begin{minted}{haskell}
  62. instance (KnownSymbol path, HasServer sublayout)
  63. => HasServer (path :> sublayout) where
  64. type ServerT (path :> sublayout) m = ServerT sublayout m
  65. route ...
  66. where
  67. pathString = symbolVal (Proxy :: Proxy path)
  68. \end{minted}
  69. \end{frame}
  70. \begin{frame}[fragile]{Server example}
  71. \begin{minted}{haskell}
  72. type Echo = Capture "echo" Text :> Get ’[PlainText] Text
  73. echoAPI :: Proxy Echo
  74. echoAPI = Proxy
  75. echoServer :: Server Echo
  76. echoServer = return
  77. \end{minted}
  78. \end{frame}
  79. \begin{frame}{servant-client}
  80. \begin{itemize}
  81. \item Generates Haskell client functions for API
  82. \item Same types as API specification: For RPC the whole ``web layer'' is abstracted away
  83. \item Also easy to use!
  84. \end{itemize}
  85. \end{frame}
  86. \begin{frame}{servant-docs, servant-js ...}
  87. Many other interpretations exist already, for example:
  88. \begin{itemize}
  89. \item Documentation generation
  90. \item Foreign function export (e.g. Elm, JavaScript)
  91. \item Mock-server generation
  92. \end{itemize}
  93. \end{frame}
  94. \section{Demo}
  95. \section{Conclusion}
  96. \begin{frame}{Drawbacks}
  97. \begin{itemize}
  98. \item Haskell has no custom open kinds (yet)
  99. \item Proxies are ugly
  100. \item Errors can be a bit daunting
  101. \end{itemize}
  102. \end{frame}
  103. \begin{frame}{Questions?}
  104. Ølkartet: github.com/tazjin/pubkartet \\
  105. Slides: github.com/tazjin/servant-presentation
  106. @tazjin
  107. \end{frame}
  108. \end{document}