[web-devel] Hamlet syntax suggestion

Michael Snoyman michael at snoyman.com
Sun May 15 07:48:40 CEST 2011


I'm definitely getting the feeling that we'll need two Hamlets. The main
question is whether there will be someone to maintain the more complicated
version. If someone wants to step up to the plate on this, please email me
and we can try to figure out how to proceed.

Michael

On Sun, May 15, 2011 at 8:13 AM, Greg Weber <greg at gregweber.info> wrote:

> back to the javascript alternatives question- someone just released a ghc
> javascript compiler with a small Yesod example.
> http://article.gmane.org/gmane.comp.lang.haskell.cafe/88970
> https://github.com/hamishmack/yesod-slides/blob/master/src/Slides.hs
>
> For hamlet proposals, I am wondering if we should consider shipping 2
> hamlets. One would continue the current goal of putting as little of haskell
> as possible in the templates. The other would use the haskell package that
> parses haskell source and let you stick whatever code in your templates that
> you desire. The benefit of the latter also being that users can better
> determine which patterns are most common in their templates and should be
> proposed for the former.
>
> On Thu, May 12, 2011 at 6:55 PM, Max Cantor <mxcantor at gmail.com> wrote:
>
>> how about adding standard haskell case matching to hamlet instead?  its
>> very general, well understood, and covers many use cases.  $if and $maybe
>> can be left in but they would basically just be sugar for the corresponding
>> case statements?  if wouldn't cover the case with the commas that neil
>> mentioned or view patterns, but would still be very general:
>>
>> $case boo of
>>  ${Left x} -> did not finish
>>  ${Right 1} -> you came in first
>>  ${Right n} -> loser
>>
>>
>>
>>
>> On May 13, 2011, at 4:08 AM, Neil Mitchell 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
>>
>>
>> _______________________________________________
>> web-devel mailing list
>> web-devel at haskell.org
>> http://www.haskell.org/mailman/listinfo/web-devel
>>
>
>
> _______________________________________________
> 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/20110515/9d7b6a0a/attachment-0001.htm>


More information about the web-devel mailing list