Date Sorting...
David Feuer
dfeuer@cs.brown.edu
Fri, 8 Mar 2002 02:52:32 -0500
On Fri, Mar 08, 2002, Ketil Z. Malde wrote:
> I don't think it's either functional nor imperative by itself. The
> question is how you structure it, do you say something like
>
> buffer x
> list y
>
> x = readFile ...
> y = parse x
> quickSort y
> print y
>
> (which would be imperative), or do you say something like
>
> print (quickSort (parse (readFile ...)))
Unfortunately, this is wrong. You'd have to do something more like
readFile ... >>= print . sort . parse
> which would be functional. Note that the only really imperative part
> is the sorting, which actually changes the content of y for the
> following part of the program. A functional implementation wouldn't
> destroy y, but create a new list with the elements from y in sorted
> order.
yah.
>
> I'm not sure if that made things clearer :-)
>
> (If you really want to implement it, look at the Prelude for some
> help, some of the things you wish to do is pretty standard fare.
> And sorting is perhaps made easier if you rearrange the list of dates
> a bit?)
Sorting is probably easiest if you use the standard sort function. I'm
still kind of interested in whether anyone has done work on which
purely-functional sorts are efficient, and particularly which ones are
efficient in GHC.
David Feuer