blaze-htmlでname属性の値を設定するときに、コンパイルエラーが出てしまった。次のようなエラー。

    Couldn't match expected type H.AttributeValue'<br />                with actual type[a0]'
In the return type of a call of concat'<br /> In the second argument of($)', namely
`concat ["s", show y, "-", show m, ....]'
In the expression: A.name $ concat ["s", show y, "-", show m, ....] 

concatを使って、name属性の値になってほしい文字列を作っているのだが、これがAttributeValue型にならないと言われる。例によってStackOverflowに解決策が出ていた:how does one get strings (not string literals) into blazehtml attributes/element contents?

AttributeValue型はIsStringのインスタンスだが、OverloadedStringsを宣言したファイルの文字列リテラルはOKでも、プログラムで作るString型は受け付けない。それで代わりにtoValue :: a -> AttributeValueを用いればよい(一番最後のMagnus Kronqvistさんのコメント)。

解決するのに1時間くらいはかかってしまった。

Comments