Context
The IHP Guide has a section that describes their use of hash symbols:
https://ihp.digitallyinduced.com/Guide/helpful-tips.html
It mentions the following:
Writing
#companyId
is equivalent to writingfromLabel @"companyId"
.
Experiment
In the example blog application, if I add the following to a view:
{get #title post}
The title of the post shows up as expected.
Now, if I add the following to the view instead:
{get (fromLabel @"title") post}
the page doesn't render properly and it gives me the following message:
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"
Question
Based on the what is mentioned in the documentation cited above, it seemed that I could write:
get (fromLabel @"title") post
instead of:
get #title post
But that clearly does not work. :-)
So, what am I missing here? Is there a way to write:
get #title post
in terms of fromLabel
?
Update 1
As suggested by Fyodor in a comment below, I tried the following:
{show @Int 42}
This was the result:
Web/View/Posts/Show.hs:11:33
• 12:23:
|
12 | {show @Int 42}
| ^
"0\nSrcLoc \"\" 1 13\nParse error in expression: show@Int\n"
CodePudding user response:
This is a known bug :-)
See https://github.com/digitallyinduced/ihp/issues/1049 and https://github.com/digitallyinduced/ihp/issues/857
Try writing it like this:
[hsx|{title}|]
where
title = get (fromLabel @"title") post
Inside HSX expressions the haskell code inside {}
is parsed using a custom haskell parser (not the one used by the haskell compiler). The custom parser is a bit outdated and doesn't support the @SomeType
syntax yet.
The #hash
syntax is also not supported directly by the parser. The parser thinks that the #
symbol is an infix operator (like
or -
). HSX later transforms the infix expressions with #
into the correct fromLabel
call.
With recent versions of the haskell compiler we can actually get rid of the third-party parser entirely and use the haskell compiler parser directly. We plan to do that in the future to fix this issue.