1

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

(or )xに変換/読み取り、関数の結果を に戻すにはどうすればよいですか?NumMaybe...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]’
4

1 に答える 1