🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.functional
Article #665

Re: SML Pretty-printing

#665
From: Andrew Koenig
Date: Tue, 06 Oct 1992 22:15
37 lines
1506 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... *)

No problem -- the program is a syntax error.

In the absence of other delimeters, a `case' eats all the clauses it can,
so in fact this program should have been indented this way:

	fun testcase (x,y) =
	  case x of
	    Alpha _ => ()
	  | Beta _ =>
	      case y of
	        Happy _ => ()
	      | Dopey _ => ()
	      | Grumpy _ => ()
	      | Gamma _ => ();

to correspond to the way it's parsed.  That in turn generates a type error.
-- 
				--Andrew Koenig
				  ark@europa.att.com
Technical Details
Message-ID: <23825@alice.att.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!att!allegra!alice!ark
References: <91849@netnews.upenn.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!att!allegra!alice!ark
From: ark@alice.att.com (Andrew Koenig)
Newsgroups: comp.lang.functional
Subject: Re: SML Pretty-printing
Message-ID: <23825@alice.att.com>
Date: 6 Oct 92 22:15:57 GMT
Article-I.D.: alice.23825
References: <91849@netnews.upenn.edu>
Reply-To: ark@alice.UUCP ()
Organization: AT&T Bell Laboratories, Murray Hill NJ
Lines: 37