Haskell Noob:QuosQuotes在Yesod中没有工作的OverloadedStrings?

时间:2015-07-02 22:25:37

标签: haskell yesod

我不确定为什么我不能让这个工作....

我的hs文件顶部有QuasiQuotes和OverloadedStrings,位于main.hs,maindevel.hs的顶部,也在我的foo.cabal文件中声明。

错误:

Couldn't match type ‘[Char]’ with ‘Text’
    Expected type: Text
    Actual type: String
In the second argument of ‘($)’, namely
    ‘renderHtml (GHC.Base.id (toHtml y))’
In the expression:
    putStrLn $ renderHtml (GHC.Base.id (toHtml y))

代码:

module Widgets.MainWidgets where
{-# LANGUAGE GADTs #-}
{-# LANGUAGE QuasiQuotes #-}                      
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE OverloadedStrings, TypeSynonymInstances, FlexibleInstances #-}
import Import

import Text.Hamlet (shamlet)
import Text.Blaze.Html.Renderer.String (renderHtml)
import Data.Char (toLower)
import Data.List (sort)
import qualified Data.Text    as T
import qualified Data.Text.IO as T

import ClassyPrelude
import Yesod
import Data.Time.Clock
import Data.Time.Calendar
import Data.Time.LocalTime
import Data.Time.Format

getCurrYear :: String
getCurrYear = formatTime defaultTimeLocale "%y" getCurrentTime

getYear :: IO ()
getYear = putStrLn $ renderHtml
    [shamlet|#{y}|]
        where y = getCurrYear

我的foo.cabal文件中也有这个:

extensions: TemplateHaskell
            QuasiQuotes
            OverloadedStrings
            NoImplicitPrelude
            CPP
            MultiParamTypeClasses
            TypeFamilies
            GADTs
            GeneralizedNewtypeDeriving
            FlexibleContexts
            EmptyDataDecls
            NoMonomorphismRestriction
            DeriveDataTypeable
            ViewPatterns
            TupleSections
            RecordWildCards
            TypeSynonymInstances
            FlexibleInstances
            DeriveGeneric

我知道为什么会出现字符串/文本转换错误? 提前致谢! 阿德里安

1 个答案:

答案 0 :(得分:3)

ClassyPrelude中的putStrLn采用Text而不是String。最简单的解决方案是将Renderer导入更改为模块的Text版本。