Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. Re: Operator orders affect parse result (m00nlight)
2. Re: Operator orders affect parse result (Francesco Ariis)
3. Re: Operator orders affect parse result (Norbert Melzer)
4. Re: Operator orders affect parse result (m00nlight)
----------------------------------------------------------------------
Message: 1
Date: Mon, 13 Apr 2015 15:49:43 +0800 (CST)
From: m00nlight <[email protected]>
To: "The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell" <[email protected]>
Subject: Re: [Haskell-beginners] Operator orders affect parse result
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"
Hi Francesco,
Thanks for your reply. But after I change the aOperators like the following, it
still produce non-correct parse result.
aOperators = [ [Prefix (reservedOp "-" >> return (Neg ))]
, [ Infix (reservedOp "*" >> return (ABinary Divide )) AssocLeft,
Infix (reservedOp "/" >> return (ABinary Multiply )) AssocLeft]
, [Infix (reservedOp "+" >> return (ABinary Add )) AssocLeft,
Infix (reservedOp "-" >> return (ABinary Subtract )) AssocLeft]
]
parse result:
*Main> parseString "res := a / b * c"
Assign "res" (ABinary Divide (ABinary Multiply (Var "a") (Var "b")) (Var "c"))
*Main>
--m00nlight
?2015?04?13 15?21?, "Francesco Ariis"<[email protected]>??:
On Mon, Apr 13, 2015 at 02:56:47PM +0800, m00nlight wrote:
> Dear Haskellers,
>
> I have tried the "while language parser" tutorial on haskellwiki, but I
> encounter an problem I can not understand here,
> The following is the code:
>
> http://pastebin.com/saC9vwCn
>
>
> So it seems that the order of the operator will affect the parse result.
> What's the problem with my code? How can I make my program to produce
> consistent parse result.
Checking the documentation for OperatorTable [1] (the first argument to
buildExpressionParser), it seems it is working as expected:
An OperatorTable s u m a is a list of Operator s u m a lists. The list
is ordered in descending precedence. All operators in one list have
the same precedence (but may have a different associativity).
I think you can take advantage of the fact that OperatorTable is /a list
of lists/, hence
aOperators = [ [Prefix (reservedOp "-" >> return (Neg ))]
, [Infix (reservedOp "/" >> return (ABinary Divide )) AssocLeft,
Infix (reservedOp "*" >> return (ABinary Multiply ))
AssocLeft]
, [Infix (reservedOp "+" >> return (ABinary Add )) AssocLeft]
, [Infix (reservedOp "-" >> return (ABinary Subtract ))
AssocLeft]
]
should do the trick (try swapping the elements in the second list.
Will this do?
[1]
http://hackage.haskell.org/package/parsec-3.0.0/docs/Text-Parsec-Expr.html#t:OperatorTable
_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20150413/66316ad0/attachment-0001.html>
------------------------------
Message: 2
Date: Mon, 13 Apr 2015 10:12:20 +0200
From: Francesco Ariis <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] Operator orders affect parse result
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
On Mon, Apr 13, 2015 at 03:49:43PM +0800, m00nlight wrote:
> Hi Francesco,
>
> Thanks for your reply. But after I change the aOperators like the following,
> it still produce non-correct parse result.
>
> aOperators = [ [Prefix (reservedOp "-" >> return (Neg ))]
> , [ Infix (reservedOp "*" >> return (ABinary Divide )) AssocLeft,
> Infix (reservedOp "/" >> return (ABinary Multiply ))
> AssocLeft]
> , [Infix (reservedOp "+" >> return (ABinary Add )) AssocLeft,
> Infix (reservedOp "-" >> return (ABinary Subtract ))
> AssocLeft]
> ]
Check those lines:
, [ Infix (reservedOp "*" >> return (ABinary Divide )) AssocLeft,
Infix (reservedOp "/" >> return (ABinary Multiply )) AssocLeft]
Divide should go on the same line of "/", not "*"! Similar fix for Multiply!
------------------------------
Message: 3
Date: Mon, 13 Apr 2015 10:29:12 +0200
From: Norbert Melzer <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Operator orders affect parse result
Message-ID:
<ca+bcvstohbzaehrhjnw7d7krrsrky4h6xmxl_vriq878kbv...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
According to the given code, that result seems to be fine... Apply / to a
and be and that result is applied to * together with c. Only odd thing is
that you named the / Multiply and the * Divide.
Am 13.04.2015 09:50 schrieb "m00nlight" <[email protected]>:
> Hi Francesco,
>
> Thanks for your reply. But after I change the aOperators like the
> following, it still produce non-correct parse result.
>
> aOperators = [ [Prefix (reservedOp "-" >> return (Neg ))]
> , [ Infix (reservedOp "*" >> return (ABinary Divide ))
> AssocLeft,
> Infix (reservedOp "/" >> return (ABinary Multiply ))
> AssocLeft]
> , [Infix (reservedOp "+" >> return (ABinary Add )) AssocLeft,
> Infix (reservedOp "-" >> return (ABinary Subtract ))
> AssocLeft]
> ]
>
>
> parse result:
>
> *Main> parseString "res := a / b * c"
> Assign "res" (ABinary Divide (ABinary Multiply (Var "a") (Var "b")) (Var
> "c"))
> *Main>
>
>
>
> --m00nlight
>
> ?2015?04?13 15?21?, "Francesco Ariis"<[email protected]>??:
>
>
> On Mon, Apr 13, 2015 at 02:56:47PM +0800, m00nlight wrote:
> > Dear Haskellers,
> >
> > I have tried the "while language parser" tutorial on haskellwiki, but I
> > encounter an problem I can not understand here,
> > The following is the code:
> >
> > http://pastebin.com/saC9vwCn
> >
> >
> > So it seems that the order of the operator will affect the parse result.
> > What's the problem with my code? How can I make my program to produce
> > consistent parse result.
>
> Checking the documentation for OperatorTable [1] (the first argument to
> buildExpressionParser), it seems it is working as expected:
>
> An OperatorTable s u m a is a list of Operator s u m a lists. The list
> is ordered in descending precedence. All operators in one list have
> the same precedence (but may have a different associativity).
>
> I think you can take advantage of the fact that OperatorTable is /a list
> of lists/, hence
>
> aOperators = [ [Prefix (reservedOp "-" >> return (Neg ))]
> , [Infix (reservedOp "/" >> return (ABinary Divide ))
> AssocLeft,
> Infix (reservedOp "*" >> return (ABinary Multiply ))
> AssocLeft]
> , [Infix (reservedOp "+" >> return (ABinary Add ))
> AssocLeft]
> , [Infix (reservedOp "-" >> return (ABinary Subtract ))
> AssocLeft]
> ]
>
> should do the trick (try swapping the elements in the second list.
> Will this do?
>
>
> [1]
> http://hackage.haskell.org/package/parsec-3.0.0/docs/Text-Parsec-Expr.html#t:OperatorTable
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
>
> <#14cb1c225ea1e3ea_>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20150413/277ba3a7/attachment-0001.html>
------------------------------
Message: 4
Date: Mon, 13 Apr 2015 16:40:42 +0800 (CST)
From: m00nlight <[email protected]>
To: "The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell" <[email protected]>
Subject: Re: [Haskell-beginners] Operator orders affect parse result
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"
Hi Norbert, Francesco,
Thanks. Just an stupid mistake when I change the code. It is actually correct.
Thanks for all your help.
--m00nlight
?2015?04?13 16?29?, "Norbert Melzer"<[email protected]>??:
According to the given code, that result seems to be fine... Apply / to a and
be and that result is applied to * together with c. Only odd thing is that you
named the / Multiply and the * Divide.
Am 13.04.2015 09:50 schrieb "m00nlight" <[email protected]>:
Hi Francesco,
Thanks for your reply. But after I change the aOperators like the following, it
still produce non-correct parse result.
aOperators = [ [Prefix (reservedOp "-" >> return (Neg ))]
, [ Infix (reservedOp "*" >> return (ABinary Divide )) AssocLeft,
Infix (reservedOp "/" >> return (ABinary Multiply )) AssocLeft]
, [Infix (reservedOp "+" >> return (ABinary Add )) AssocLeft,
Infix (reservedOp "-" >> return (ABinary Subtract )) AssocLeft]
]
parse result:
*Main> parseString "res := a / b * c"
Assign "res" (ABinary Divide (ABinary Multiply (Var "a") (Var "b")) (Var "c"))
*Main>
--m00nlight
?2015?04?13 15?21?, "Francesco Ariis"<[email protected]>??:
On Mon, Apr 13, 2015 at 02:56:47PM +0800, m00nlight wrote:
> Dear Haskellers,
>
> I have tried the "while language parser" tutorial on haskellwiki, but I
> encounter an problem I can not understand here,
> The following is the code:
>
> http://pastebin.com/saC9vwCn
>
>
> So it seems that the order of the operator will affect the parse result.
> What's the problem with my code? How can I make my program to produce
> consistent parse result.
Checking the documentation for OperatorTable [1] (the first argument to
buildExpressionParser), it seems it is working as expected:
An OperatorTable s u m a is a list of Operator s u m a lists. The list
is ordered in descending precedence. All operators in one list have
the same precedence (but may have a different associativity).
I think you can take advantage of the fact that OperatorTable is /a list
of lists/, hence
aOperators = [ [Prefix (reservedOp "-" >> return (Neg ))]
, [Infix (reservedOp "/" >> return (ABinary Divide )) AssocLeft,
Infix (reservedOp "*" >> return (ABinary Multiply ))
AssocLeft]
, [Infix (reservedOp "+" >> return (ABinary Add )) AssocLeft]
, [Infix (reservedOp "-" >> return (ABinary Subtract ))
AssocLeft]
]
should do the trick (try swapping the elements in the second list.
Will this do?
[1]
http://hackage.haskell.org/package/parsec-3.0.0/docs/Text-Parsec-Expr.html#t:OperatorTable
_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20150413/ec128bc3/attachment.html>
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 82, Issue 13
*****************************************