首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Happstack.lite教程未能使用“非法类型签名:‘`String'”进行编译

Happstack.lite教程未能使用“非法类型签名:‘`String'”进行编译
EN

Stack Overflow用户
提问于 2014-08-24 08:40:15
回答 1查看 390关注 0票数 0

我一直在学习Happstack.Lite教程:http://www.happstack.com/page/view-page-slug/9/happstack-lite-tutorial非常成功,但我似乎无法克服这个编译错误:

代码语言:javascript
复制
$ ghc crashcourse.hs -o crashcourse
[1 of 1] Compiling Main             ( crashcourse.hs, crashcourse.o )

crashcourse.hs:52:21:
    Illegal type signature: `String'
      Perhaps you intended to use -XScopedTypeVariables
    In a pattern type-signature

有关守则:

代码语言:javascript
复制
echo :: ServerPart Response
echo =
    path $ \(msg :: String) ->
        ok $ template "echo" $ do
          p $ "echo says: " >> toHtml msg
          p "Change the url to echo something else."

上下文中的代码:( {-# LANGUAGE OverloadedStrings #-}实用程序对此问题没有影响,它是为解决其他问题而添加的)

代码语言:javascript
复制
{-# LANGUAGE OverloadedStrings #-}
module Main where

import Control.Applicative ((<$>), optional)
import Data.Maybe (fromMaybe)
import Data.Text (Text)
import Data.Text.Lazy (unpack)
import Happstack.Lite
import Text.Blaze.Html5 (Html, (!), a, form, input, p, toHtml, label)
import Text.Blaze.Html5.Attributes (action, enctype, href, name, size, type_, value)
import qualified Text.Blaze.Html5 as H
import qualified Text.Blaze.Html5.Attributes as A

main :: IO ()
main = serve Nothing myApp

myApp :: ServerPart Response
myApp = msum
  [ dir "echo"    $ echo
   ,dir "query"   $ queryParams
--  , dir "form"    $ formPage
--  , dir "fortune" $ fortune
--  , dir "files"   $ fileServing
--  , dir "upload"  $ upload
  , homePage
  ]

template :: Text -> Html -> Response
template title body = toResponse $
  H.html $ do
    H.head $ do
      H.title (toHtml title)
    H.body $ do
      body
      p $ a ! href "/" $ "back home"

homePage :: ServerPart Response
homePage =
    ok $ template "home page" $ do
           H.h1 "Hello!"
           H.p "Writing applications with happstack-lite is fast and simple!"
           H.p "Check out these killer apps."
           H.p $ a ! href "/echo/secret%20message" $ "echo"
           H.p $ a ! href "/query?foo=bar" $ "query parameters"
           H.p $ a ! href "/form" $ "form processing"
           H.p $ a ! href "/fortune" $ "(fortune) cookies"
           H.p $ a ! href "/files" $ "file serving"
           H.p $ a ! href "/upload" $ "file uploads"

echo :: ServerPart Response
echo =
    path $ \(msg :: String) ->
        ok $ template "echo" $ do
          p $ "echo says: " >> toHtml msg
          p "Change the url to echo something else."

queryParams :: ServerPart Response
queryParams =
    do mFoo <- optional $ lookText "foo"
       ok $ template "query params" $ do
         p $ "foo is set to: " >> toHtml (show mFoo)
         p $ "change the url to set it to something else."

我已经成功地从这里中执行了此操作。

代码语言:javascript
复制
module Main where

import Control.Monad    (msum)
import Happstack.Server (nullConf, simpleHTTP, ok, dir, path, seeOther)

main :: IO ()
main = simpleHTTP nullConf $
  msum [ dir "hello" $ path $ \s -> ok $ "Hello, " ++ s
       , seeOther "/hello/Haskell" "/hello/Haskell"
       ]

您的帮助将不胜感激!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-08-24 09:40:14

正如随意书教程中所提到的,您需要下面的语用:

代码语言:javascript
复制
{-# LANGUAGE OverloadedStrings, ScopedTypeVariables #-}

如果我添加ScopedTypeVariables,它对我有效。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25469966

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档