[web-devel] Hamlet and functions that take multiple arguments

Michael Snoyman michael at snoyman.com
Sun Jul 25 07:53:32 EDT 2010


On Sun, Jul 25, 2010 at 1:00 PM, Mark Bradley <barkmadley at gmail.com> wrote:

> On Sun, Jul 25, 2010 at 3:40 AM, Michael Snoyman <michael at snoyman.com>
> wrote:
> > Implementing that feature was amazingly simple. I'm still not 100% sold
> on
> > the syntax, as I'm worried it's complicated Hamlet too much. But having
> the
> > feature available probably isn't too dangerous. It also doesn't cause any
> > problems with existing code as far as my tests go.
> > As a bonus, the $forall/$maybe issue was very easy to solve: just
> surround
> > it with parentheses.
> > [$hamlet|
> > $forall ((foo bar) baz) bin
> >    $bin$
> > |]
>
> well done on being so quick.  I didn't even get a chance to try and
> implement it myself.
>
> The code looks very clean and accurate.  Should the spaces allowed
> argument be propagated to the sub expression parser derefParens?
>
> It's not necessary; the only reason to disallow spaces is when dealing with
a $forall et al. However, once inside parentheses, we can allow the spaces
without ambiguity.

Also doesn't parsec have a between combinator?
>
> i.e.
>    derefParens as = between (char '(') (char ')') (deref as)
>    derefSingle as = derefParens as <|> fmap DerefLeaf ident
>    deref spaceAllowed = do
>        let delim = if spaceAllowed
>                        then (char '.' <|> (many1 (char ' ') >> return ' '))
>                        else char '.'
>        x <- derefSingle spaceAllowed
>        xs <- many $ delim >> derefSingle
>        return $ foldr1 DerefBranch $ x : xs
>
> I wasn't aware of between, cleaned up the code nicely. Thanks! Unless
there's objections, I'll release the new code as Hamlet 0.4.1.

Michael
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/web-devel/attachments/20100725/a9bdd065/attachment.html


More information about the web-devel mailing list