首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >哈斯克尔幸福栈

哈斯克尔幸福栈
EN

Stack Overflow用户
提问于 2015-04-15 10:15:29
回答 1查看 284关注 0票数 0

尝试使用意外堆栈,让它正确地安装在窗口上,但现在它正在排除一些错误,当我编译我的测试类,任何输入都会被感激。

代码语言:javascript
复制
module Main where

import Happstack.Server
import           Text.Blaze ((!))
import qualified Text.Blaze.Html4.Strict as H
import qualified Text.Blaze.Html4.Strict.Attributes as A

appTemplate :: String -> [H.Html] -> H.Html -> H.Html
appTemplate title headers body =
H.html $ do
  H.head $ do
    H.title (H.toHtml title)
    H.meta ! A.httpEquiv "Content-Type"
           ! A.content "text/html;charset=utf-8"
    sequence_ headers
  H.body $ do
    body

helloBlaze :: ServerPart Response
helloBlaze =
ok $ toResponse $
appTemplate "Hello, Blaze!"
            [H.meta ! A.name "keywords"
                    ! A.content "happstack, blaze, html"
            ]
            (H.p $ do "Hello, "
                      H.b "blaze-html!")

main :: IO ()
main = simpleHTTP nullConf $ helloBlaze

我创建了一个粒子堆栈文件夹,并使用阴谋将所需的文件安装到这个文件夹中,但是当我编译代码时,我会看到下面的错误。

代码语言:javascript
复制
Main.hs:13:30:
Couldn't match expected type ‘H.AttributeValue’
            with actual type ‘[Char]’
In the first argument of ‘A.httpEquiv’, namely ‘"Content-Type"’
In the second argument of ‘(!)’, namely
  ‘A.httpEquiv "Content-Type"’
In the first argument of ‘(!)’, namely
  ‘H.meta ! A.httpEquiv "Content-Type"’

Main.hs:14:28:
Couldn't match expected type ‘H.AttributeValue’
            with actual type ‘[Char]’
In the first argument of ‘A.content’, namely
  ‘"text/html;charset=utf-8"’
In the second argument of ‘(!)’, namely
  ‘A.content "text/html;charset=utf-8"’
In a stmt of a 'do' block:
  H.meta ! A.httpEquiv "Content-Type"
  ! A.content "text/html;charset=utf-8"

Main.hs:23:34:
Couldn't match expected type ‘H.AttributeValue’
            with actual type ‘[Char]’
In the first argument of ‘A.name’, namely ‘"keywords"’
In the second argument of ‘(!)’, namely ‘A.name "keywords"’
In the first argument of ‘(!)’, namely ‘H.meta ! A.name "keywords"’

Main.hs:24:37:
Couldn't match expected type ‘H.AttributeValue’
            with actual type ‘[Char]’
In the first argument of ‘A.content’, namely
  ‘"happstack, blaze, html"’
In the second argument of ‘(!)’, namely
  ‘A.content "happstack, blaze, html"’
In the expression:
  H.meta ! A.name "keywords" ! A.content "happstack, blaze, html"

Main.hs:26:27:
 Couldn't match type ‘[]’ with ‘Text.Blaze.Internal.MarkupM’

 Expected type: Text.Blaze.Internal.MarkupM Char
   Actual type: [Char]
 In a stmt of a 'do' block: "Hello, "
 In the second argument of ‘($)’, namely
   ‘do { "Hello, ";
         H.b "blaze-html!" }’
 In the third argument of ‘appTemplate’, namely
   ‘(H.p
     $ do { "Hello, ";
            H.b "blaze-html!" })’

Main.hs:27:31:
Couldn't match type ‘[Char]’ with ‘Text.Blaze.Internal.MarkupM ()’
Expected type: H.Html
  Actual type: [Char]
In the first argument of ‘H.b’, namely ‘"blaze-html!"’
In a stmt of a 'do' block: H.b "blaze-html!"
In the second argument of ‘($)’, namely
  ‘do { "Hello, ";
        H.b "blaze-html!" }’
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-04-15 10:37:50

像这样的台词:

代码语言:javascript
复制
Couldn't match expected type ‘H.AttributeValue’
        with actual type ‘[Char]’

编译器抱怨说它希望接收H.AttributeValue,但得到了[Char]

AttributeValue被定义为这里。正如您所看到的,它是IsString的一个实例,这意味着您可以使用作为语言扩展的OverloadedStrings。为了使它能够

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

在你档案的顶端。

这将重写如下片段:

代码语言:javascript
复制
A.httpEquiv "Content-Type"

像这样的事情:

代码语言:javascript
复制
A.httpEquiv (fromString "Content-Type")

fromString来自定义为这里IsString类,如:

代码语言:javascript
复制
class IsString a where
    fromString :: String -> a
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29647571

复制
相关文章

相似问题

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