# How to typeset Haskell ++ operator and friends?

Usually, the list concatenation operator in Haskell is printed as overlapping double plus signs in books.

(In ASCII it is just ++)

What are other Haskell operators which could be typeset more beautiful in LaTeX?

-
have you checked ctan.org/tex-archive/info/symbols/comprehensive –  Willie Wong Oct 16 '10 at 14:59

I couldn’t find the symbol in symbols, but it is easy enough to define:

\newcommand\doubleplus{+\kern-1.3ex+\kern0.8ex}
\newcommand\mdoubleplus{\ensuremath{\mathbin{+\mkern-10mu+}}}


This produces

If you use xelatex or lualatex with unicode-math, you can just write ⧺ (U+29FA DOUBLE PLUS) or its alias \doubleplus. This gives (with XITS fonts)

-

I don't agree that [u]sually, the list concatenation operator in Haskell is printed as overlapping double plus signs in books, instead most manuscripts about Haskell prefer to use ASCII (sometimes monotype, sometimes with additional highlighting) for representing Haskell operations. The exceptions are generally authors concerned with equational reasoning in Haskell, influenced by the Bird-Meertens formalism.

The issue, I think, is that Haskell has a lot of multi-character, non-alphabetical infix operators. The Haskell 98 Report has !!, ^^, **, ==, /=, <=, >=, &&, ||, >>, >>=, and \$!, of which only a few obviously correspond to a glyph. Making up your own risks confusion: even the relatively obvious-seeming map of == to ≡ does confuse. Losing the property of mapping your pretty-printed code to something you can type in is a very serious problem in a Haskell paper. The issue is less serious in a book-length treatment, but it is still there. So I recommend using a package like minted.

If you really do want to represent "++", I find Caramdir's solution puts the two vertical lines too close together. Gibbons (1994), An Introduction to the Bird-Meertens Formalism place the lines a little wider apart, but even wider, where each segment of the trisected line is equal, looks more attractive still to my eyes:

\documentclass{minimal}
\def\drawplusplus#1#2#3{\hbox to 0pt{\hbox to #1{\hfill\vrule height #3 depth
0pt width #2\hfill\vrule height #3 depth 0pt width #2\hfill
}}\vbox to #3{\vfill\hrule height #2 depth 0pt width
#1 \vfill}}
%Poor man's typography
\def\concat{\mathrel{\drawplusplus {12pt}{0.4pt}{5pt}}}
%It would be better to specify these in font-relative measures, but it
%probably doesn't scale anyway.
\begin{document}
$x = y \concat z$
\end{document}

-
+1 especially for the first half. –  DevSolar Oct 24 '11 at 14:33

These might be a bit obvious, but the -> is nice as → (U+2192 RIGHTWARDS ARROW), => as ⇒ (U+21D2 RIGHTWARDS DOUBLE ARROW), and <- as ← (U+2190 LEFTWARDS ARROW).

I felt that Programming in Haskell by Graham Hutton was nicely put together. You can find an example of it from here: http://www.cs.nott.ac.uk/~gmh/solutions.pdf Maybe it can give you some ideas.

There is also lhs2TeX, but I found its output to be rather bloated.

-