Last active
February 23, 2021 17:49
-
-
Save wenkokke/97b9055aae4c05842a16713a722839ff to your computer and use it in GitHub Desktop.
Directives for formatting linear types using lhs2TeX.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%if False | |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
% linear.fmt | |
% | |
% Format -> as a period when part of a lambda abstraction, | |
% as a lolli when used as part of a linear function arrow, | |
% and as an arrow otherwise. | |
% | |
% Wen Kokke, February 2021, version 1.0 | |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
%endif | |
% | |
%if not lhs2tex_lambda_fmt_read | |
%let lhs2tex_lambda_fmt_read = True | |
%include lhs2TeX.fmt | |
% | |
%if style /= newcode | |
% | |
%format % = percent_ "\hsPercentCmd " | |
%format 1 = one_ "\hsOneCmd " | |
%format \ = lambda_ "\hsLambdaCmd " | |
%format -> = "\hsArrow{" `arrow_` "}{" `lineararrow_` "}{" lambdaperiod_ "}" | |
%format percent_ = "\%" | |
%format one_ = "1" | |
%format lambda_ = "\lambda " | |
%format `arrow_` = "\rightarrow " | |
%format `lineararrow_` = "\multimap " | |
%format lambdaperiod_ = "\mathpunct{.}" | |
% | |
\ReadOnlyOnce{linear.fmt} | |
\makeatletter | |
% The HaskellResetHook is a list to which things can | |
% be added that reset the Haskell state to the beginning. | |
% This is to recover from states where the hacked intelligence | |
% is not sufficient. | |
\let\HaskellResetHook\empty | |
\newcommand*{\AtHaskellReset}[1]{% | |
\g@@addto@@macro\HaskellResetHook{#1}} | |
\newcommand*{\HaskellReset}{\HaskellResetHook} | |
\newcommand*\hsNoOp{} | |
\newcommand*\hsUnrestrictedArrow[3]{#1} | |
\newcommand*\hsLinearArrow[3]{#2\global\let\hsArrow=\hsUnrestrictedArrow} | |
\newcommand*\hsLambdaPeriod[3]{#3\global\let\hsArrow=\hsUnrestrictedArrow} | |
\newcommand\hsPercentCmd{\global\let\hsOneCmd=\hsOneAfterPercentCmd} | |
\newcommand*\hsOneAfterPercentCmd{% | |
\global\let\hsOneCmd=\hsNoOp | |
\global\let\hsArrow=\hsLinearArrow} | |
\newcommand\hsLambdaCmd{\global\let\hsArrow=\hsLambdaPeriod} | |
\AtHaskellReset{% | |
\global\let\hsOneCmd=\hsNoOp | |
\global\let\hsArrow=\hsUnrestrictedArrow} | |
\HaskellReset | |
\makeatother | |
\EndFmtInput | |
%endif | |
%endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment