上下文
IHP指南中有一节描述了它们对散列符号的使用:
https://ihp.digitallyinduced.com/Guide/helpful-tips.html
它提到以下几点:
Writing
#companyId等同于编写fromLabel @"companyId"。
实验
在示例博客应用程序中,如果我将以下内容添加到视图中:
{get #title post}这篇文章的标题如预期的那样出现。
现在,如果我将以下内容添加到视图中:
{get (fromLabel @"title") post}页面没有正确呈现,它给了我以下消息:
Web/View/Posts/Show.hs:11:33
• 12:40:
|
12 | {get (fromLabel @"title") post}
| ^
"0\nSrcLoc \"\" 1 30\nParse error in expression: fromLabel@\"title\"\n"问题
基于上述文件中提到的内容,我似乎可以这样写:
get (fromLabel @"title") post而不是:
get #title post但这显然行不通。:-)
我在这里错过了什么?有没有办法写:
get #title post就fromLabel而言
更新1
正如费奥多在下面的评论中所建议的那样,我尝试了以下几点:
{show @Int 42}结果是:
Web/View/Posts/Show.hs:11:33
• 12:23:
|
12 | {show @Int 42}
| ^
"0\nSrcLoc \"\" 1 13\nParse error in expression: show@Int\n"发布于 2021-08-28 07:23:22
更新:这在IHPV0.20中得到了修正,现在与预期的一样工作。
这是一个已知的bug :-)
见https://github.com/digitallyinduced/ihp/issues/1049和https://github.com/digitallyinduced/ihp/issues/857
试着写成这样:
[hsx|{title}|]
where
title = get (fromLabel @"title") post在HSX表达式中,{}中的haskell代码使用自定义haskell解析器(而不是haskell编译器使用的解析器)解析。自定义解析器有点过时,还不支持@SomeType语法。
解析器也不直接支持#hash语法。解析器认为#符号是一个infix运算符(如+或-)。HSX稍后将使用#的infix表达式转换为正确的fromLabel调用。
使用haskell编译器的最新版本,我们实际上可以完全摆脱第三方解析器,直接使用haskell编译器解析器。我们计划在将来这样做来解决这个问题。
https://stackoverflow.com/questions/68960202
复制相似问题