Haskell programmers have an undue reputation for writing obfuscated code, perhaps due to the fondness for pointfree code and higher-order functions. However the commitment to terseness is dubious at best; syntax is rarely exploited.
Constructor Declarations
Constructors need only be separated by |
, and the deriving
clause can be on
the same line:
data G = A Int | B | C deriving (Eq, Ord)
Instance Declarations
Instance declarations can be written on a single line:
instance Show A where show=show.pretty
Type Signatures
One can declare several type signatures at once, viz.
succ, φ :: Int -> Int
with definitions elsewhere in the file
succ n=n+1
φ = ...
Spacing Operators/Composition
Operators (including the composition operator) need not be separated from
identifiers by whitespace, one can write f.g.h
for f . g . h
.
Where Clauses
Where clauses can be on the same line as an expression, viz.
cata f=c where c=f.fmap c.project
Clauses
Pattern-match clauses can be separated by semicolons rather than newlines, viz.
isL L{}=True; isL _=False
Imports
Imports can be separated by semicolon:
import Data.List(foldl');import qualified Data.ByteString as BS
Braces and Semicolons
Do-Notation
do
-notation with braces allows us to write do
-blocks on a single line, e.g.
do {c <- libc; m <- dlsym c "malloc"; f <- dlsym c "free"; dlclose c$>(m, f)}
Case Expressions
Likewise, case
expressions can fit in a single line:
case asm of {Label lϵ -> void $ fm lϵ; _ -> pure ()}