【发布时间】:2015-08-11 22:06:37
【问题描述】:
我刚开始使用 haskell,但遇到了基本的“echo”REST 服务器的问题。
Spock 看起来是 REST 服务器的一个不错的起点,虽然我掌握了 State monad 的基础知识,但在理解如何在 spock 代码周围放置 runState 时遇到了问题。
这是我目前得到的代码。
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Data.Monoid
import Web.Spock.Safe
import qualified Control.Monad.State as S
storeData :: String -> S.State String String
storeData val = do S.put val
return val
getData :: S.State String String
getData = do val <- S.get
return val
main :: IO ()
main =
runSpock 11350 $ spockT id $
do get "store" $
text "Would be a call to getData"
【问题讨论】:
-
这个谜题的关键是
spockT的第一个参数,你需要为m ~ State String提供它。但是,您将遇到与 in this answer 解释的完全相同的问题:State String不会在处理程序调用之间自动持久化。
标签: rest haskell monads state-monad haskell-spock