我尝试将 GET 参数传递给函数并从结果中连接一个字符串
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Data.Monoid ((<>))
import Web.Scotty
f x = x <> x
main = do
scotty 3000 $ do
get "/f/:x" $ do
x <- param "x"
text ("f(" <> x <> ") = " <> f x)
为了使我的应用程序更加有趣,我想使用一个需要 Num 参数类型实例的函数,例如
f x = x * x
我如何转换/读取x
到 a Num
(or Maybe...
) 并将函数结果转换回 a Data.Text.Internal.Lazy.Text
?
我试过
text ("f(" <> x <> ") = " <> (show $ f $ read x))
这会产生错误:
• Couldn't match expected type
‘text-1.2.3.1:Data.Text.Internal.Lazy.Text’
with actual type ‘[Char]’