how to see operators precedence in GHCi

Hello , from http://community.livejournal.com/ru_declarative/54566.html Q: how to see operators precedence in GHCi? A: Prelude> let showParen = (undefined::[[[[()]]]]->()) Prelude> showParen $ 2+3*4 <interactive>:1:12: No instance for (Num [[[[()]]]]) arising from use of `+' at <interactive>:1:12 Probable fix: add an instance declaration for (Num [[[[()]]]]) In the second argument of `($)', namely `2 + (3 * 4)' In the definition of `it': it = showParen $ (2 + (3 * 4)) Prelude> -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com

Bulat Ziganshin
Hello ,
from http://community.livejournal.com/ru_declarative/54566.html
Q: how to see operators precedence in GHCi? A: Prelude> let showParen = (undefined::[[[[()]]]]->()) Prelude> showParen $ 2+3*4 <interactive>:1:12: No instance for (Num [[[[()]]]]) arising from use of `+' at <interactive>:1:12 Probable fix: add an instance declaration for (Num [[[[()]]]]) In the second argument of `($)', namely `2 + (3 * 4)' In the definition of `it': it = showParen $ (2 + (3 * 4))
Hmm, OK, but not that much quicker than going Prelude> :info (*) class (Eq a, Show a) => Num a where ... (*) :: a -> a -> a ... -- Defined in GHC.Num infixl 7 * Prelude> :info (+) class (Eq a, Show a) => Num a where (+) :: a -> a -> a ... -- Defined in GHC.Num infixl 6 + Prelude> -- Jón Fairbairn Jon.Fairbairn@cl.cam.ac.uk

Hello Jon, Wednesday, July 25, 2007, 8:07:57 PM, you wrote:
Q: how to see operators precedence in GHCi? In the definition of `it': it = showParen $ (2 + (3 * 4))
Hmm, OK, but not that much quicker than going Prelude> :info (*)
it just my poor english :) i mean - "how to see how Haskell will parse some expression?". it will be too slow to look up each precedence and parse expression by hand :) -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com

On Wed, Jul 25, 2007 at 09:35:38PM +0400, Bulat Ziganshin wrote:
Hello Jon,
Wednesday, July 25, 2007, 8:07:57 PM, you wrote:
Q: how to see operators precedence in GHCi? In the definition of `it': it = showParen $ (2 + (3 * 4))
Hmm, OK, but not that much quicker than going Prelude> :info (*)
it just my poor english :) i mean - "how to see how Haskell will parse some expression?". it will be too slow to look up each precedence and parse expression by hand :)
Much easier: stefan@stefans:~$ ghci GHCi, version 6.7.20070712: http://www.haskell.org/ghc/ :? for help Loading package base ... linking ... done. Prelude> :set -ddump-parsed Prelude> 2 + 3 * 4 ==================== Parser ==================== Just (2 + 3) * 4 14 Prelude> Stefan

On Wed, Jul 25, 2007 at 10:55:56AM -0700, Stefan O'Rear wrote:
On Wed, Jul 25, 2007 at 09:35:38PM +0400, Bulat Ziganshin wrote:
Hello Jon,
Wednesday, July 25, 2007, 8:07:57 PM, you wrote:
Q: how to see operators precedence in GHCi? In the definition of `it': it = showParen $ (2 + (3 * 4))
Hmm, OK, but not that much quicker than going Prelude> :info (*)
it just my poor english :) i mean - "how to see how Haskell will parse some expression?". it will be too slow to look up each precedence and parse expression by hand :)
Much easier:
stefan@stefans:~$ ghci GHCi, version 6.7.20070712: http://www.haskell.org/ghc/ :? for help Loading package base ... linking ... done. Prelude> :set -ddump-parsed Prelude> 2 + 3 * 4
==================== Parser ==================== Just (2 + 3) * 4
14 Prelude>
Uhm... that didn't work :) Not quite as nice: stefan@stefans:~$ ghci -ddump-rn-trace GHCi, version 6.7.20070712: http://www.haskell.org/ghc/ :? for help Top level: tcRnStmt let __cmCompileExpr = System.IO.stdout let __cmCompileExpr = GHC.Handle.stdout [(rw, GHC.Handle.stdout)] Loading package base ... linking ... done. Top level: tcRnStmt let __cmCompileExpr = System.IO.stderr let __cmCompileExpr = GHC.Handle.stderr [(rjJ, GHC.Handle.stderr)] Top level: tcRnStmt let __cmCompileExpr = System.IO.stdin let __cmCompileExpr = GHC.Handle.stdin [(rq, GHC.Handle.stdin)] Prelude> 2 + 3 * 4 Top level: tcRnStmt (2 + 3) * 4 2 + (3 * 4) [(rqz, +), (rqA, *)] 14 Prelude> Stefan

| Uhm... that didn't work :) | | Not quite as nice: | | stefan@stefans:~$ ghci -ddump-rn-trace You probably wanted -ddump-rn Simon

On Thu, Jul 26, 2007 at 12:42:52AM +0100, Simon Peyton-Jones wrote:
| Uhm... that didn't work :) | | Not quite as nice: | | stefan@stefans:~$ ghci -ddump-rn-trace
You probably wanted -ddump-rn
Seemed so, but that option has no effect (bug?): stefan@stefans:~$ ghci -ddump-rn GHCi, version 6.7.20070712: http://www.haskell.org/ghc/ :? for help Loading package base ... linking ... done. Prelude> 2 + 2 4 Prelude> Stefan

Hmm. Good point. Fixed. Smion | -----Original Message----- | From: Stefan O'Rear [mailto:stefanor@cox.net] | Sent: 26 July 2007 01:01 | To: Simon Peyton-Jones | Cc: Bulat Ziganshin; haskell-cafe@haskell.org; Jon Fairbairn | Subject: Re: [Haskell-cafe] Re: how to see operators precedence in GHCi | | On Thu, Jul 26, 2007 at 12:42:52AM +0100, Simon Peyton-Jones wrote: | > | > | Uhm... that didn't work :) | > | | > | Not quite as nice: | > | | > | stefan@stefans:~$ ghci -ddump-rn-trace | > | > You probably wanted -ddump-rn | | Seemed so, but that option has no effect (bug?): | | stefan@stefans:~$ ghci -ddump-rn | GHCi, version 6.7.20070712: http://www.haskell.org/ghc/ :? for help | Loading package base ... linking ... done. | Prelude> 2 + 2 | 4 | Prelude> | | Stefan
participants (4)
-
Bulat Ziganshin
-
Jon Fairbairn
-
Simon Peyton-Jones
-
Stefan O'Rear