Using UTCTime with Hamlet

时间秒杀一切 提交于 2019-12-01 07:34:43

Without investigating the actual error, I think your approach is not great. You will very likely eventually want several ways of formatting a UTCTime, after all, the type is there to store times, not just dates. By giving a ToMarkup UTCTime instance, you fix this globally.

I would recommend to write functions renderAsDate :: UTCDate -> HTML, renderAsTime :: UTCDate -> HTML etc. and use them in your template, e.g. #{renderAsDate (newsItemDate entry)}.

But this won’t solve the runtime error, which comes from the serialization layer and is likely independent of your templates.

Tehnix

I'm pretty sure you could just use show in the hamlet? That's atleast what I've done...

#{show $ newsItemDate entry}

I've run into this instance thing before, and as this guy describes here it's something like this:

As part of this philosophy of frugality of expression Haskell doesn’t require type signatures — although an experienced Haskeller provides them for clarity — so type errors in this strongly typed language are often cryptic for the uninitiated. For instance, if you define a function f that adds two numbers and then call it with two strings, the compiler will not complain about bad arguments, it will complain about string not supporting operator plus. And it will formulate this complaint in a very non-obvious way. [1] Under "1. Haskell is Terse"...

[1] http://fpcomplete.com/ten-things-you-should-know-about-haskell-syntax/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!