[web-devel] Hamlet variables: (foo bar) baz or foo (bar baz)

Matt Brown matt at softmechanics.net
Fri Dec 31 09:51:43 CET 2010


I like parentheses, since we'd be able to use the interpolation
character (whatever it ends up being) within the interpolation.
However, I'd prefer the template haskell style $(...).

I wonder if hamlet could leverage haskell-src-exts-qq, which defines
quasiquoters for haskell code.  I've used it myself, and although it's
been a while and I'm a bit hazy on the details, I remember that it
worked rather well.  One gotcha I remember is that it didn't usually
know correct fixities for operators etc, which could lead to quite
confusing errors.  This may have improved since I last looked at it,
though.

-matt

On Thu, Dec 30, 2010 at 11:31 PM, Aur Saraf <sonoflilit at gmail.com> wrote:
> On Fri, Dec 31, 2010 at 8:57 AM, Michael Snoyman <michael at snoyman.com> wrote:
>> I thought I would start this in a separate thread. Right now in
>> Hamlet, $foo.bar.baz$ (or equivalently $foo bar baz$ gets converted to
>> the Haskell code "foo (bar baz)". This makes a fair bit of sense for
>> the period-delimited syntax, but feels very wrong for the
>> space-delimited syntax. So the question is: should we change things
>> around? That would mean we would need to modify our current templates
>> to include extra parentheses, eg:
>>
>>    $foo.bar.baz$ -> $foo (bar baz)$
>>    $a.b.c.d$ -> $a (b (c d))$
>>
>> I suppose that, in theory, if we actually change the variable
>> interpolation character to a percent sign, we could take back the
>> dollar sign to work like Haskell, eg:
>>
>>    $a.b.c.d$ -> %a $ b $ c d%
>>
>> And just since I brought *that* up: we could consider using a
>> different symbol for variable interpolation than the percent sign,
>> such as a hash or ampersand. However, both of those already have
>> special meaning (hash == id, ampersand == HTML escape character), so I
>> don't know how well that would work. There was talk once upon a time
>> of merging the syntax for dollar-sign and caret interpolation, which
>> now that we've added some more polymorphism it might be possible.
>>
>> Caveat: I haven't actually written any code for this, so I don't know
>> how feasible it is. I'm basically throwing out ideas as they come to
>> me.
>>
>> Michael
>
> HAML uses #{some haskell here} for interpolation (which is ruby
> syntax). HAML implementations in other languages stayed with that. We
> could too.
>
> Is it really impossible to just use the plaintext as code in Template
> Haskell? It would really be nice if you could use any bit of Haskell
> wherever you can use a variable (but it's just nice-to-have, not worth
> playing with GHC's code just to get it).
>
> If it is impossible, I'm all for $ doing what it's supposed to... but
> that way lies reimplementing Haskell parsing, and I'm not sure you
> want to go there (we'll add more and more requests as we got more and
> more syntax...)
>
> _______________________________________________
> web-devel mailing list
> web-devel at haskell.org
> http://www.haskell.org/mailman/listinfo/web-devel
>



More information about the web-devel mailing list