SMLFORMAT(1)
SMLFORMAT(1) π
okay bestie, welcome to the General Commands Manual section, page 1, and today's main character is smlformat β the pretty printer generator for SML# β¨ (yes, that's literally what the NAME says, we're not skipping anything here π«Ά)
β¨ NAME β¨
smlformat β the pretty printer generator for SML# π
π SYNOPSIS π
smlformat [--stdout|--output=file] [--with-line-directive] filename ...
like. look at it. so clean. so iconic. π
πΈ DESCRIPTION πΈ
okay so here's the tea, bestie π SMLFormat generates pretty printing functions for ML types and datatypes. That's the whole vibe.
The input file is an SML# program, and every type and datatype in it is annotated by formatting comments βοΈ. The smlformat command interprets the definition of types and its formatting comments, and then inserts formatting functions into the input program. So it's giving "glow-up but for your source code" β¨. And the generated programs can be compiled by the SML# compiler, no cap π₯.
When multiple input files are given, each input file is separately read and yields a separate program π. By default, the output file name is obtained by appending .sml suffix to the input file name. (so ex.ppg becomes ex.ppg.sml, cute right? π)
π OPTIONS π
--stdoutβ Output the result to the standard output. straight to your terminal, no file, no drama π--output=filenameβ Output the result to the specified file. you pick the name, you pick the destiny β¨--with-line-directiveβ Insert comments about the line number of the input file into the output. receipts, but for line numbers π§Ύ--separate=structureNameβ Output formatters in a separate structure. formatters get their own little apartment π
π¦ EXAMPLES π¦
okay this is the part where it gets real. The following is a minimal example of an input file ex.ppg:
(*% *)
datatype intlist = NIL | CONS of int * intlist
fun pretty_intlist x =
SMLFormat.prettyPrint nil (format_intlist x)
where (*% *) is the formatting comment of the intlist type. yes bestie, that tiny little comment is doing SO much work π
By invoking smlformat,
smlformat ex.ppg
it interprets the formatting comment and generates format_intlist function of type intlist -> SMLFormat.format. In the output file ex.ppg.sml, the definition of format_intlist is inserted just after the definition of the intlist type. it just slips in there. ate. π
heads up bestie!! π¨ To compile the generated program, you need to write an interface fileex.ppg.smiby yourself. no autopilot for this one, sorry. In the interface file, the SMLFormat librarysmlformat-lib.smimust be required. The content ofex.ppg.smimust be as follows:
_require "basis.smi"
_require "smlformat-lib.smi"
datatype intlist = NIL | CONS of int * intlist
val format_intlist : intlist -> SMLFormat.format
val pretty_intlist : intlist -> string
like. gorgeous. no notes. π
π SEE ALSO π
- SML# Document, available at
https://www.pllab.riec.tohoku.ac.jp/smlsharp/docs/
and that's the whole page babes, from the SMLFORMAT(1) up top all the way down to that little SMLFORMAT(1) footer at the bottom β that's the man page name stamped on the last line, the version/source line of the General Commands Manual π go forth and pretty-print, you absolute icon πβ¨π
π¦ where this page comes from
- debian trixie: smlsharp 4.1.0-1+b1 Β· MIT
- ubuntu jammy: smlsharp 4.0.0+git20211227.5af5945b-1 Β· MIT
- ubuntu noble: smlsharp 4.0.0+git20211227.5af5945b-2 Β· MIT
- ubuntu questing: smlsharp 4.1.0-1
- ubuntu resolute: smlsharp 4.1.0-1.1 Β· MIT
- ubuntu stonking: smlsharp 4.1.0-1.1 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms