🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.functional
Article #667

Re: SML Pretty-printing

#667
From: Karl-Filip Faxen
Date: Wed, 07 Oct 1992 11:23
53 lines
2672 bytes
In article <91849@netnews.upenn.edu>, freeman@linc.cis.upenn.edu (Jon Freeman) writes:
|> Regarding SML, kff@dentex.tds.kth.se (Karl-Filip Faxen) says:
|> 
|> >|> and it seems to be difficult to indent automatically as well.
|> >
|> >In an Emacs mode, perhaps. In a pretty printer, certainly not (I've
|> >written one).
|> >
|> >Cheers,
|> >         Karl-Filip
|> 
|> I never even thought that writing a pretty-printer for SML was a
|> feasible undertaking.  Consider the following program:

OOPS! I was comparing pretty-printing curried application and
applications involving tuples. I didn't say I'd written a 
pretty-printer for SML (I haven't; it's for a subset of Haskell).

|> --------------------------------------------------------------
|> 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... *)
|> --------------------------------------------------------------
|> 
|> Any pretty-printer that can correctly indent the last line of testcase
|> has to be able to discriminate between the constructors of foo and the
|> constructors of bar!!  Does your pretty-printer really do this?  If
|> so, I'm very impressed.

This isn't a problem of pretty-printing, it's a problem of parsing!
Actually, for your example to be syntactically correct, you have 
to have either a layout dependent syntax or (which I understand you 
to mean) a context dependent syntax. That would be really wierd for
a modern programming language! Given, however, that the parsing 
problem is solved and I have an abstract syntax tree, it wouldn't 
be _that_ difficult to produce this layout (it wouldn't be difficult 
at all if you produced something that was parsable with a context-
independent parser).

Cheers,
          Karl-Filip

------------------------------------------------------------
Make the frequent case fast, and the fast case frequent!
Technical Details
Message-ID: <1992Oct7.112326.21692@kth.se>
Path: arc1-ca.pugleaf.net!sparky!uunet!mcsun!sunic!kth.se!dentex.tds.kth.se!kff
References: <91849@netnews.upenn.edu>

Show Full Headers
Complete Article Headers
Newsgroups: comp.lang.functional
Path: arc1-ca.pugleaf.net!sparky!uunet!mcsun!sunic!kth.se!dentex.tds.kth.se!kff
From: kff@dentex.tds.kth.se (Karl-Filip Faxen)
Subject: Re: SML Pretty-printing
Message-ID: <1992Oct7.112326.21692@kth.se>
Sender: usenet@kth.se (Usenet)
Nntp-Posting-Host: dentex.tds.kth.se
Reply-To: kff@dentex.tds.kth.se (Karl-Filip Faxen)
Organization: Royal Institute of Technology, Stockholm, Sweden
References:  <91849@netnews.upenn.edu>
Date: Wed, 7 Oct 1992 11:23:26 GMT
Lines: 53