Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
GHC
GHC
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,248
    • Issues 4,248
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
    • Iterations
  • Merge Requests 391
    • Merge Requests 391
  • Requirements
    • Requirements
    • List
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
  • Security & Compliance
    • Security & Compliance
    • Dependency List
    • License Compliance
  • Operations
    • Operations
    • Incidents
    • Environments
  • Analytics
    • Analytics
    • CI / CD
    • Code Review
    • Insights
    • Issue
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #8751

Closed
Open
Opened Feb 08, 2014 by Icelandjack@IcelandjackReporter

Show parenthesised output of expressions in ghci

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:

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 ¹] Developer beliefs about binary operator precedence

[=#point2 ²] Brace Yourself (tweet)

Edited Mar 10, 2019 by Icelandjack
Assignee
Assign to
8.0.1
Milestone
8.0.1 (Past due)
Assign milestone
Time tracking
None
Due date
None
Reference: ghc/ghc#8751