🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.functional
Article #671

Re: SML Pretty-printing

#671
From: Stephen Adams
Date: Thu, 08 Oct 1992 08:05
69 lines
2936 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:
 > 
 > --------------------------------------------------------------
 > 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.

Is this legal?  NJ/SML gives me a type error. Whether the
Gamma choice belongs to case x or case y is purely a matter
of syntax, and so I would hope that the pretty printer gets
it `wrong', otherwise it would be misleading!  To get what
you want you have to put the case y in parentheses of a `let
in ... end'

	- fun testcase (x,y) =
	=   case x of
	=     Alpha _ => ()
	=   | Beta _ =>
	=       case y of
	=         Happy _ => ()
	=       | Dopey _ => ()
	=       | Grumpy _ => ()
	=   | Gamma _ => ();   
	std_in:8.7-12.17 Error: rules don't agree (tycon mismatch)
	  expected: bar -> unit
	  found:    foo -> unit
	  rule:
	    Gamma _ => ()
	- 

I find that the Emacs SML mode by Lars Bo Nielsen
(lbn@iesd.auc.dk) adequate (I use version 2.5, this might
now be antique, the file has creation date 1989).
Occasionally it does things that I don't like but I am
prepared to correct them manually (or as often just accept
them).
--
Stephen Adams                           Email: S.R.Adams@ecs.soton.ac.uk
Electronics and Computer Science        Tel: 0703 593649
University of Southampton               Fax: 0703 593045 
Southampton  SO9 5NH,  UK
Technical Details
Message-ID: <SRA.92Oct8090533@landin.ecs.soton.ac.uk>
Path: arc1-ca.pugleaf.net!sparky!uunet!mcsun!uknet!doc.ic.ac.uk!sot-ecs!sra
References: <91849@netnews.upenn.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!mcsun!uknet!doc.ic.ac.uk!sot-ecs!sra
From: sra@ecs.soton.ac.uk (Stephen Adams)
Newsgroups: comp.lang.functional
Subject: Re: SML Pretty-printing
Message-ID: <SRA.92Oct8090533@landin.ecs.soton.ac.uk>
Date: 8 Oct 92 08:05:33 GMT
References: <91849@netnews.upenn.edu>
Sender: news@ecs.soton.ac.uk
Organization: Southampton University Computer Science
Lines: 69
Nntp-Posting-Host: landin
In-reply-to: freeman@linc.cis.upenn.edu's message of 6 Oct 92 16:20:53 GMT