🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.functional
Article #663

Re: SML Pretty-printing

#663
From: Andrew Wright
Date: Tue, 06 Oct 1992 19:44
43 lines
2053 bytes
In article <91849@netnews.upenn.edu> freeman@linc.cis.upenn.edu (Jon Freeman) writes:
>I never even thought that writing a pretty-printer for SML was a
>feasible undertaking.  Consider the following program:
>
>--------------------------------------------------------------
>datatype foo = Alpha of int | Beta of real | Gamma of string;
>datatype bar = Happy of int | Dopey of real | Grumpy of string;
>
>fun testcase (x,y) =
>  case x of
>    Alpha _ => ()
>  | Beta _ =>
>      case y of
>        Happy _ => ()
>      | Dopey _ => ()
>      | Grumpy _ => ()
>  | Gamma _ => ();       (* Hmmm... *)
>--------------------------------------------------------------

This example is bogus.  The last line belongs to the case statment,
not the function (hence this program is not type correct).  Your
naive pretty printer would fix the misleading indentation.

Good pretty printing simply involves building a _full_ parser for the
language, choosing a canonical format for expressions, and rules for
line breaking.

The problem is that my choice of canonical format may not be yours.
ML suffers from this to a greater degree than Lisp.  But note that
Lisp/Scheme also suffers from this problem.  My scheme mode indents as:

   (and one-long-name second-long-name third-long-name fourth-long-name
     fifth-long-name)

but (sometimes) I would rather have:

   (and one-long-name second-long-name third-long-name fourth-long-name
        fifth-long-name)

In fact, the scheme mode has a list of special names and a rule about
length of names to choose between the two ways.

Andrew Wright
Technical Details
Message-ID: <BvptHK.Cop@rice.edu>
Path: arc1-ca.pugleaf.net!sparky!uunet!ogicse!uwm.edu!wupost!newsfeed.rice.edu!rice!gefion.cs.rice.edu!wright
References: <91849@netnews.upenn.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!ogicse!uwm.edu!wupost!newsfeed.rice.edu!rice!gefion.cs.rice.edu!wright
From: wright@gefion.cs.rice.edu (Andrew Wright)
Newsgroups: comp.lang.functional
Subject: Re: SML Pretty-printing
Message-ID: <BvptHK.Cop@rice.edu>
Date: 6 Oct 92 19:44:08 GMT
Article-I.D.: rice.BvptHK.Cop
References: <91849@netnews.upenn.edu>
Sender: news@rice.edu (News)
Organization: Rice University, Houston
Lines: 43