[clean-list] questions

Tomasz Zielonka t.zielonka@students.mimuw.edu.pl
Mon, 24 Nov 2003 00:13:38 +0100


On Mon, Nov 24, 2003 at 10:10:58AM +1100, Fergus Henderson wrote:
> On 20-Nov-2003, Tomasz Zielonka <t.zielonka@zodiac.mimuw.edu.pl> wrote:
> > On Thu, Nov 20, 2003 at 05:26:36PM +0100, Jenda Krynicky wrote:
> > 
> > date = do
> >     yyyy <- count 4 digit
> >     char '-'
> >     mm <- count 2 digit
> >     char '-'
> >     dd <- count 2 digit
> >     return (yyyy, mm, dd)
> > 
> > Is it really so long and cryptic?
> 
> No!  "\d{4}" is cryptic!  "yyyy <- count 4 digit" is elegant and reasonably
> concise without being cryptic.

Agreed!

> With suitable abbreviations,
> 
> 	c = char
> 	r = count	-- r for "repeat"
> 	d = digit
> 
> you could make it a one-liner:
> 
> 	do{yyyy<-r 4 d;c '-';mm<-r 2 d;c '-';dd<-r 2 d;return(yyyy,mm,dd); }

This one is a bit shorter, but a lot more cryptic :)

	return(,,)`ap`(4`r`d)`ap`(c '-'>>2`r`d)`ap`(c '-'>>2`r`d)

(you have to import Monad(ap))

> But I hope you will agree that such source code compression harms readability
> and that this code, *just like regexps*, is unnecessarily cryptic.

Sure!

Best regards,
Tom

-- 
.signature: Too many levels of symbolic links