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

Aur Saraf sonoflilit at gmail.com
Fri Dec 31 08:31:04 CET 2010


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...)



More information about the web-devel mailing list