Infix operators in Hamlet: yes or no?

39 views
Skip to first unread message

Michael Snoyman

unread,
Mar 28, 2012, 5:37:16 AM3/28/12
to yeso...@googlegroups.com
We discussed this a bit last week, but let's get it out in the open:
do we want infix operators in Hamlet?

I'm strongly leaning towards taking them all out (sans $, as Max mentioned).

Relevant Github issue: https://github.com/yesodweb/yesod/issues/278

Luite Stegeman

unread,
Mar 28, 2012, 11:23:21 AM3/28/12
to yeso...@googlegroups.com

I personally like to have them, but only if they actually work in all
situations (or at least when there's a very clear distinction between
what's supported an what's not). So if the current implementation is
giving problems, I'd say remove support until there's something that
actually does work.


luite

Vagif Verdi

unread,
Mar 28, 2012, 11:30:23 AM3/28/12
to yeso...@googlegroups.com
If it is an implementation problem, then it is understandable.
Otherwise i do not see the reason to treat infix functions differently.

Michael Snoyman

unread,
Mar 28, 2012, 12:34:39 PM3/28/12
to yeso...@googlegroups.com
That's a funny comment: the whole feature is to tree infix operators
differently! That's at the crux of the matter: is this an extra
difference that should be reflected in Hamlet? If we're following the
dumb language theory, it might be overkill.

Vagif Verdi

unread,
Mar 28, 2012, 1:20:44 PM3/28/12
to yeso...@googlegroups.com
Perhaps i missed the relevant discussion. Could you please point me to it so i can see what are the reasons to treat infix operations differently.


On Wednesday, March 28, 2012 9:34:39 AM UTC-7, Michael Snoyman wrote:
That's a funny comment: the whole feature is to tree infix operators
differently! That's at the crux of the matter: is this an extra
difference that should be reflected in Hamlet? If we're following the
dumb language theory, it might be overkill.

Michael Snoyman

unread,
Mar 28, 2012, 1:30:49 PM3/28/12
to yeso...@googlegroups.com

Felipe Almeida Lessa

unread,
Mar 28, 2012, 1:37:16 PM3/28/12
to yeso...@googlegroups.com
On Wed, Mar 28, 2012 at 6:37 AM, Michael Snoyman <mic...@snoyman.com> wrote:
> I'm strongly leaning towards taking them all out (sans $, as Max mentioned).

+1 for taking them out.

--
Felipe.

Max Cantor

unread,
Mar 28, 2012, 2:50:53 PM3/28/12
to yeso...@googlegroups.com
There seems to be people who think that Hamlet should stick with the x . y . z $ v style convention. Maybe we include (.) and ($) and just treat them interchangeably in hamlet. its kind of a hack but might appease them

max

mifrai

unread,
Mar 28, 2012, 2:51:25 PM3/28/12
to yeso...@googlegroups.com
I agree with Luite. They're nice to have, but if they're causing problems - I'd rather see them go than cause more confusion.

But, just to be clear, if I wanted to use an infix operator - would I still be able to do the following?
  $if (==) a b
    etc

On Wednesday, March 28, 2012 2:37:16 AM UTC-7, Michael Snoyman wrote:
On Wednesday, March 28, 2012 2:37:16 AM UTC-7, Michael Snoyman wrote:
On Wednesday, March 28, 2012 2:37:16 AM UTC-7, Michael Snoyman wrote:

Max Cantor

unread,
Mar 28, 2012, 2:54:56 PM3/28/12
to yeso...@googlegroups.com
This is an important point, but should be easy to support. We just need to make sure we parse (..) as a normal function..

Max

mifrai

unread,
Mar 28, 2012, 3:04:09 PM3/28/12
to yeso...@googlegroups.com
I'm not sure I like this. While it would work in that specific case - it can lead to a lot of confusion if anybody tries to use it for anything else. For example, in lenses or for actual function composition:

$for x <- map (a . b) $ getL (la . lb) c
  #{x}

While it's arguable whether you should be doing something like that in the templates, I would say that treating (.) as ($) makes hamlet context switching more difficult than I would feel comfortable with.

Patrick Hurst

unread,
Mar 28, 2012, 4:48:31 PM3/28/12
to yeso...@googlegroups.com
I'm in favor of keeping them; it would be absurd IMO if you had to introduce a name for the function (* 5) in the surrounding context just so that you could multiply things by five.

Could you use haskell-src-exts for doing the parsing and then just evaluate the AST?

Greg Weber

unread,
Mar 28, 2012, 5:50:34 PM3/28/12
to yeso...@googlegroups.com
we don't want a haskell-src-extras dependency. A new version was just
released that should work well with 7.4. Historically it has lagged
behind GHC releases. If someone wanted to create a haskell-src-extras
version of Haskell we are very open to that possibility, but we don't
think we can make it the default.

Michael Snoyman

unread,
Mar 29, 2012, 12:31:43 AM3/29/12
to yeso...@googlegroups.com

Patrick Hurst

unread,
Mar 29, 2012, 12:35:59 AM3/29/12
to yeso...@googlegroups.com
Is $ support still a planned feature?

On Wednesday, March 28, 2012 at 11:31 PM, Michael Snoyman wrote:

Michael Snoyman

unread,
Mar 29, 2012, 12:40:28 AM3/29/12
to yeso...@googlegroups.com
Yes, it's already there. $ was never actually including as part of
infix operators, but as syntactic sugar of Shakespeare. You can see
here[1] that $ was explicitly excluded from the infix parsing.

[1] https://github.com/yesodweb/shakespeare/blob/40b6496ace781aabbefaa470f10a7ddab283b5f6/shakespeare/Text/Shakespeare/Base.hs#L107

Reply all
Reply to author
Forward
0 new messages