[web-devel] Hamlet syntax suggestion
Greg Weber
greg at gregweber.info
Thu May 12 22:20:57 CEST 2011
import Text.Coffee
Gives you coffescript templates like Julius. But it isn't truly a first
class citizen yet- you can't just use it anywhere javascript is used yet.
That ability is slated for the next release. You might also be interested in
lambdascript (basically a direct translation of haskell to javascript) or
jmacro (more like your suggestion).
Greg Weber
On Thu, May 12, 2011 at 1:08 PM, Neil Mitchell <ndmitchell at gmail.com> wrote:
> Hi,
>
> I am thinking of doing a project using Hamlet (and perhaps a little of
> Yesod, I'm not quite sure). As I was reading through the book
> (excellent resource!) I was surprised by the syntax for $maybe, in
> particular that you get case matching on only the Maybe type. Being
> used to Haskell I'm a fan of general solutions, so I commented on the
> book (http://www.yesodweb.com/book/templates#c5). Since book comments
> aren't really the right place to discuss something technical I thought
> I'd move it here.
>
> Currently Hamlet has:
>
> $if a; $elseif b; $else
>
> $maybe x <- ma; $nothing
>
> I think if $if was expanded to be pattern guards, rather than boolean
> expressions, it would be more powerful, yet remain just as easy to
> use. So, I'd like:
>
> $if Just x <- ma
>
> To be equivalent to:
>
> $maybe x <- ma
>
> Then $else and $nothing also become equivalent.
>
> If you also allow commas you can write things like:
>
> $if Just x <- age, x > 18
> adults
> $else
> kids
>
> These have a very simple explanation - they're just pattern guards.
> Michael wants Hamlet to remain simple, in order to allow designers to
> use it without knowing programming. I think that's a reasonable goal,
> but I don't think a richer syntax for $if would make it any harder in
> the common case. I also think that if inexperienced people have to do
> more advanced tricks - i.e. converting their ADT into nested Maybe
> values in order to do some case analysis, it's going to end up harder
> in the long run.
>
> I had two other, smaller thoughts, while reading the book:
>
> 1) $for x <- xs, x > 12 could be used to generalise $for to list
> comps. However, I notice you've got $for working over anything
> Foldable, rather than just lists, so it's not necessarily such a clear
> conversion. It's probably also less useful - since filter isn't too
> bad - and you can always do $for x <- [x | x <- xs, x > 12]
>
> 2) CoffeeScript makes Javascript much more useful. It would be very
> cool if as well as Julius there was something more like CoffeeScript,
> or perhaps exactly CoffeeScript. I also idly wondered if you could
> translate Haskell syntax to Javascript (without the types), but
> perhaps that isn't such a great idea.
>
> Thanks, Neil
>
> _______________________________________________
> web-devel mailing list
> web-devel at haskell.org
> http://www.haskell.org/mailman/listinfo/web-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/web-devel/attachments/20110512/7b64218a/attachment.htm>
More information about the web-devel
mailing list