[GHC] #8751: Show parenthesised output of expressions in ghci

#8751: Show parenthesised output of expressions in ghci ------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: Iceland_jack Type: feature request | Status: new Priority: normal | Milestone: Component: GHCi | Version: 7.6.3 Keywords: | Operating System: Unknown/Multiple Architecture: Unknown/Multiple | Type of failure: None/Unknown Difficulty: Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | ------------------------------------+------------------------------------- Operator fixity can be a source of bugs (even for experienced users!),[#point1 (1)] precedence levels may vary between languages and then there are user-defined operators. Attached is a patch for a ghci command allowing users to quickly parenthesise expressions as a sanity check (and as an alternative to using :info and parsing the result yourself). The command itself is activated with `:paren`: {{{ ghci> :paren 2 + 10 * 4 / 3 2 + ((10 * 4) / 3) ghci> :paren \a b → a == b || b && a == (b == a) || b \ a b -> (a == b) || ((b && (a == (b == a))) || b) ghci> :paren 5 + 1 `mod` 2 5 + (1 `mod` 2) ghci> :paren 5 * 1 `mod` 2 (5 * 1) `mod` 2 }}} A friend of mine also pointed out that this could eventually be integrated into `haskell-mode` where the user could temporarily replace an expression with a parenthesised version or have different colours indicate different levels of logical nesting. [=#point1 (1)] [http://www.knosof.co.uk/cbook/accu06.html Developer beliefs about binary operator precedence] -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8751 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8751: Show parenthesised output of expressions in ghci -------------------------------------+------------------------------------ Reporter: Iceland_jack | Owner: igloo Type: feature request | Status: new Priority: normal | Milestone: Component: GHCi | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Changes (by Iceland_jack): * owner: Iceland_jack => igloo -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8751#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8751: Show parenthesised output of expressions in ghci -------------------------------------+------------------------------------ Reporter: Iceland_jack | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: GHCi | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Changes (by Iceland_jack): * owner: igloo => -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8751#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8751: Show parenthesised output of expressions in ghci -------------------------------------+------------------------------------ Reporter: Iceland_jack | Owner: Type: feature request | Status: patch Priority: normal | Milestone: Component: GHCi | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Changes (by Iceland_jack): * status: new => patch -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8751#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8751: Show parenthesised output of expressions in ghci -------------------------------------+------------------------------------- Reporter: | Owner: Iceland_jack | Status: infoneeded Type: feature | Milestone: 7.10.1 request | Version: 7.6.3 Priority: normal | Keywords: Component: GHCi | Architecture: Unknown/Multiple Resolution: | Difficulty: Unknown Operating System: | Blocked By: Unknown/Multiple | Related Tickets: Type of failure: | None/Unknown | Test Case: | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Changes (by thoughtpolice): * status: patch => infoneeded * milestone: => 7.10.1 Comment: Please: - Add documentation about the new parameter. - Add some tests. - Squash these commits together (easier to land all at once.) Thanks! -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8751#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8751: Show parenthesised output of expressions in ghci -------------------------------------+------------------------------------- Reporter: | Owner: Iceland_jack | Status: patch Type: feature | Milestone: 7.10.1 request | Version: 7.6.3 Priority: normal | Keywords: Component: GHCi | Architecture: Unknown/Multiple Resolution: | Difficulty: Unknown Operating System: | Blocked By: Unknown/Multiple | Related Tickets: Type of failure: | None/Unknown | Test Case: | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Changes (by monoidal): * status: infoneeded => patch -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8751#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8751: Show parenthesised output of expressions in ghci -------------------------------------+------------------------------------- Reporter: | Owner: Iceland_jack | Status: infoneeded Type: feature | Milestone: 7.10.1 request | Version: 7.6.3 Priority: normal | Keywords: Component: GHCi | Architecture: Unknown/Multiple Resolution: | Difficulty: Unknown Operating System: | Blocked By: Unknown/Multiple | Related Tickets: Type of failure: | None/Unknown | Test Case: | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Changes (by thoughtpolice): * status: patch => infoneeded Comment: Sorry I missed this Iceland_Jack, can you rebase this patch? I don't think it applies on HEAD anymore I'm afraid (but I may have missed something). -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8751#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8751: Show parenthesised output of expressions in ghci -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: Type: feature request | Status: infoneeded Priority: normal | Milestone: Component: GHCi | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by RyanGlScott): Iceland_jack, this patch looks wonderful! Do you mind submitting it as a Diff via Phabricator? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8751#comment:10 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8751: Show parenthesised output of expressions in ghci -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: Type: feature request | Status: infoneeded Priority: normal | Milestone: Component: GHCi | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by Iceland_jack): Replying to [comment:10 RyanGlScott]:
Iceland_jack, this patch looks wonderful! Do you mind submitting it as a Diff via Phabricator?
I revisited it and some GHC internals had changed, I'll finish #12057 and #12045 and then get right on it :) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8751#comment:11 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8751: Show parenthesised output of expressions in ghci -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: Type: feature request | Status: infoneeded Priority: normal | Milestone: Component: GHCi | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Description changed by Iceland_jack: @@ -2,2 +2,2 @@ - users!),[#point1 (1)] precedence levels may vary between languages and - then there are user-defined operators. + users!),[#point1 ¹][#point2 ²] precedence levels may vary between + languages and then there are user-defined operators. @@ -9,1 +9,2 @@ - {{{ + + {{{#!hs @@ -25,2 +26,6 @@ - [=#point1 (1)] [http://www.knosof.co.uk/cbook/accu06.html Developer - beliefs about binary operator precedence] + [=#point1 ¹] [http://www.knosof.co.uk/cbook/accu06.html Developer beliefs + about binary operator precedence] + [=#point2 ²] + [http://ieeexplore.ieee.org/document/7548903/?platform=hootsuite Brace + Yourself] ([https://twitter.com/ieeesoftware/status/791882437295038464 + tweet]) New description: Operator fixity can be a source of bugs (even for experienced users!),[#point1 ¹][#point2 ²] precedence levels may vary between languages and then there are user-defined operators. Attached is a patch for a ghci command allowing users to quickly parenthesise expressions as a sanity check (and as an alternative to using :info and parsing the result yourself). The command itself is activated with `:paren`: {{{#!hs ghci> :paren 2 + 10 * 4 / 3 2 + ((10 * 4) / 3) ghci> :paren \a b → a == b || b && a == (b == a) || b \ a b -> (a == b) || ((b && (a == (b == a))) || b) ghci> :paren 5 + 1 `mod` 2 5 + (1 `mod` 2) ghci> :paren 5 * 1 `mod` 2 (5 * 1) `mod` 2 }}} A friend of mine also pointed out that this could eventually be integrated into `haskell-mode` where the user could temporarily replace an expression with a parenthesised version or have different colours indicate different levels of logical nesting. [=#point1 ¹] [http://www.knosof.co.uk/cbook/accu06.html Developer beliefs about binary operator precedence] [=#point2 ²] [http://ieeexplore.ieee.org/document/7548903/?platform=hootsuite Brace Yourself] ([https://twitter.com/ieeesoftware/status/791882437295038464 tweet]) -- -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8751#comment:12 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8751: Show parenthesised output of expressions in ghci -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: Type: feature request | Status: infoneeded Priority: normal | Milestone: Component: GHCi | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Description changed by Iceland_jack: @@ -2,1 +2,1 @@ - users!),[#point1 ¹][#point2 ²] precedence levels may vary between + users!),[#point1 ¹] [#point2 ²] precedence levels may vary between @@ -28,0 +28,1 @@ + New description: Operator fixity can be a source of bugs (even for experienced users!),[#point1 ¹] [#point2 ²] precedence levels may vary between languages and then there are user-defined operators. Attached is a patch for a ghci command allowing users to quickly parenthesise expressions as a sanity check (and as an alternative to using :info and parsing the result yourself). The command itself is activated with `:paren`: {{{#!hs ghci> :paren 2 + 10 * 4 / 3 2 + ((10 * 4) / 3) ghci> :paren \a b → a == b || b && a == (b == a) || b \ a b -> (a == b) || ((b && (a == (b == a))) || b) ghci> :paren 5 + 1 `mod` 2 5 + (1 `mod` 2) ghci> :paren 5 * 1 `mod` 2 (5 * 1) `mod` 2 }}} A friend of mine also pointed out that this could eventually be integrated into `haskell-mode` where the user could temporarily replace an expression with a parenthesised version or have different colours indicate different levels of logical nesting. [=#point1 ¹] [http://www.knosof.co.uk/cbook/accu06.html Developer beliefs about binary operator precedence] [=#point2 ²] [http://ieeexplore.ieee.org/document/7548903/?platform=hootsuite Brace Yourself] ([https://twitter.com/ieeesoftware/status/791882437295038464 tweet]) -- -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8751#comment:13 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8751: Show parenthesised output of expressions in ghci -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: Type: feature request | Status: infoneeded Priority: normal | Milestone: Component: GHCi | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- @@ -26,0 +26,4 @@ + ---- + + An example that is tricky for me is `calculateBmi w h = w / h^2`. + New description: Operator fixity can be a source of bugs (even for experienced users!),[#point1 ¹] [#point2 ²] precedence levels may vary between languages and then there are user-defined operators. Attached is a patch for a ghci command allowing users to quickly parenthesise expressions as a sanity check (and as an alternative to using :info and parsing the result yourself). The command itself is activated with `:paren`: {{{#!hs ghci> :paren 2 + 10 * 4 / 3 2 + ((10 * 4) / 3) ghci> :paren \a b → a == b || b && a == (b == a) || b \ a b -> (a == b) || ((b && (a == (b == a))) || b) ghci> :paren 5 + 1 `mod` 2 5 + (1 `mod` 2) ghci> :paren 5 * 1 `mod` 2 (5 * 1) `mod` 2 }}} A friend of mine also pointed out that this could eventually be integrated into `haskell-mode` where the user could temporarily replace an expression with a parenthesised version or have different colours indicate different levels of logical nesting. ---- An example that is tricky for me is `calculateBmi w h = w / h^2`. [=#point1 ¹] [http://www.knosof.co.uk/cbook/accu06.html Developer beliefs about binary operator precedence] [=#point2 ²] [http://ieeexplore.ieee.org/document/7548903/?platform=hootsuite Brace Yourself] ([https://twitter.com/ieeesoftware/status/791882437295038464 tweet]) -- Comment (by Iceland_jack): No -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8751#comment:14 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8751: Show parenthesised output of expressions in ghci -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: (none) Type: feature request | Status: infoneeded Priority: normal | Milestone: Component: GHCi | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Old description:
Operator fixity can be a source of bugs (even for experienced users!),[#point1 ¹] [#point2 ²] precedence levels may vary between languages and then there are user-defined operators.
Attached is a patch for a ghci command allowing users to quickly parenthesise expressions as a sanity check (and as an alternative to using :info and parsing the result yourself). The command itself is activated with `:paren`:
{{{#!hs ghci> :paren 2 + 10 * 4 / 3 2 + ((10 * 4) / 3) ghci> :paren \a b → a == b || b && a == (b == a) || b \ a b -> (a == b) || ((b && (a == (b == a))) || b) ghci> :paren 5 + 1 `mod` 2 5 + (1 `mod` 2) ghci> :paren 5 * 1 `mod` 2 (5 * 1) `mod` 2 }}}
A friend of mine also pointed out that this could eventually be integrated into `haskell-mode` where the user could temporarily replace an expression with a parenthesised version or have different colours indicate different levels of logical nesting.
----
An example that is tricky for me is `calculateBmi w h = w / h^2`.
[=#point1 ¹] [http://www.knosof.co.uk/cbook/accu06.html Developer beliefs about binary operator precedence]
[=#point2 ²] [http://ieeexplore.ieee.org/document/7548903/?platform=hootsuite Brace Yourself] ([https://twitter.com/ieeesoftware/status/791882437295038464 tweet])
New description: [https://www.reddit.com/r/haskell/comments/605o3b/add_a_describe_command_to_y... reddit thread]. ---- Operator fixity can be a source of bugs (even for experienced users!),[#point1 ¹] [#point2 ²] precedence levels may vary between languages and then there are user-defined operators. Attached is a patch for a ghci command allowing users to quickly parenthesise expressions as a sanity check (and as an alternative to using :info and parsing the result yourself). The command itself is activated with `:paren`: {{{#!hs ghci> :paren 2 + 10 * 4 / 3 2 + ((10 * 4) / 3) ghci> :paren \a b → a == b || b && a == (b == a) || b \ a b -> (a == b) || ((b && (a == (b == a))) || b) ghci> :paren 5 + 1 `mod` 2 5 + (1 `mod` 2) ghci> :paren 5 * 1 `mod` 2 (5 * 1) `mod` 2 }}} A friend of mine also pointed out that this could eventually be integrated into `haskell-mode` where the user could temporarily replace an expression with a parenthesised version or have different colours indicate different levels of logical nesting. ---- An example that is tricky for me is `calculateBmi w h = w / h^2`. [=#point1 ¹] [http://www.knosof.co.uk/cbook/accu06.html Developer beliefs about binary operator precedence] [=#point2 ²] [http://ieeexplore.ieee.org/document/7548903/?platform=hootsuite Brace Yourself] ([https://twitter.com/ieeesoftware/status/791882437295038464 tweet]) -- Comment (by Iceland_jack): Examples: {{{#!hs pattern (:=) :: [String] -> [String] -> [String] pattern xs:=ys <- (break (== "=") -> (xs, "=":ys)) splitArgs (words -> fn:args:=rest) = ... }}} Both `(fn:args):=rest` and `fn:(args:=rest)` parse, to see which one it is one either has to know the fixity rules, know `infixr 5 :`, know the default fixity (running the command `:info :=` currently does not divulge such secrets) or you could think of inputs (or have QuickCheck generate..) that give a different result.. neither ideal. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8751#comment:15 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC