Хаскелл Хаппстек

пытаясь использовать happstack, он правильно установился в Windows, но теперь он выдает некоторые ошибки, когда я компилирую свой тестовый класс, любой вклад будет оценен.

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

Я создал папку happstack и использовал cabal для установки необходимых файлов в эту папку, но когда я компилирую код, я получаю следующие ошибки.

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!" }’

person Community    schedule 15.04.2015    source источник
comment
Вы включили расширение OverloadedStrings (добавьте его поверх файла {-# LANGUAGE OverloadedStrings #-} или используйте аргумент командной строки -XOverloadedStrings)?   -  person Random Dev    schedule 15.04.2015
comment
{-# LANGUAGE OverloadedStrings #-}   -  person    schedule 15.04.2015
comment
Именно это? До или после модуля Главное где?   -  person    schedule 15.04.2015


Ответы (1)


В таких строках:

Couldn't match expected type ‘H.AttributeValue’
        with actual type ‘[Char]’

компилятор жалуется, что ожидал получить H.AttributeValue, а получил [Char].

AttributeValue определяется здесь< /а>. Как видите, это экземпляр IsString, а это значит, что вы можете использовать OverloadedStrings, которое является расширением языка. Чтобы включить его, поставьте

{-# LANGUAGE OverloadedStrings #-}

в верхней части вашего файла.

Это перепишет фрагменты следующим образом:

A.httpEquiv "Content-Type"

к чему-то вроде этого:

A.httpEquiv (fromString "Content-Type")

а fromString происходит из класса IsString, который определен здесь, как:

class IsString a where
    fromString :: String -> a
person zudov    schedule 15.04.2015