parentheses-less: left associative dollar operator

[ bsd3, library, system ] [ Propose Tags ] [ Report a vulnerability ]

Built-in $ (dollar operator) in Haskell has the lowest priotity possible - 0 and this requires using parentheses in situations like follows, because even a custom comparison operator cannot go lower than 0.

tests =
  [ pure (3 + 2) == Just 5
  , runReader (pure 3) 0 == 3
  , runReader ask (1 + 2) == 3
  , runReader ((+4) <$> ask) 1 + 2 == 7
  , s3 (8 `div` 3) (2 * 2) (2 + 2) == 10
  , s4 (11 `mod` 3) (8 `div` 3) (2 * 2) (2 + 2) == 12
  ]

Flipping associativity of the operator from right to left helps with reducing parentheses:

import ParenthesesLess

go = (==)
infixl 0 go

tests =
  [ s3 % 8 `div` 3 % 2 * 2 % 2 + 2 `go` 10
  , s3 % 8 `div` 3 + 1 % 2 * 2 % 2 + 2 `go` 11
  , s4 % 11 `mod` 3 % 8 `div` 3 % 2 * 2 % 2 + 2 `go` 12 
  ]

Unicode comma-like operator

Percent is easy to type, but it mixes with arithmetic expressions it is coined to separate. A Unicode comma-like symbol, such as cedilla, offers better visual perception.

import ParenthesesLess

go = (==)
infixl 1 go

tests =
  [ s3 ¸ 8 `div` 3 ¸ 2 * 2 ¸ 2 + 2 `go` 10
  , s3 ¸ 8 `div` 3 + 1 ¸ 2 * 2 ¸ 2 + 2 `go` 11
  , s4 ¸ 11 `mod` 3 ¸ 8 `div` 3 ¸ 2 * 2 ¸ 2 + 2 `go` 12
  
  , runExcept ¸ when ¸¸ 3 < 4 ¸¸ throwE () `go` Left ()
  , runExcept ¸ when ¸¸ 3 > 4 ¸¸ throwE () `go` Right ()
  , runWriter ¸ tell [True] >> tell [False] `go` ((), [True, False])
  , runReader ¸ runWriterT ¸¸ tell [True] >>> lift ask ¸ 3 `go` (3, [True])
  
  ]

Development environment

HLS should be available inside the default dev shell.

$ nix develop
$ cabal build
$ cabal test

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.0.1
Change log changelog.md
Dependencies base (>=4.7 && <5) [details]
Tested with ghc ==9.14.1
License BSD-3-Clause
Copyright Daniil Iaitkov 2026
Author Daniil Iaitskov
Maintainer dyaitskov@gmail.com
Uploaded by DaniilIaitskov at 2026-11-29T11:43:27Z
Category System
Home page http://github.com/yaitskov/parentheses-less
Bug tracker https://github.com/yaitskov/parentheses-less/issues
Source repo head: git clone https://github.com/yaitskov/parentheses-less.git
Distributions
Downloads 3 total (3 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]