Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!cs.utexas.edu!uunet!mcsun!ukc!harrier.ukc.ac.uk!mr3 From: mr3@ukc.ac.uk (M.Rizzo) Newsgroups: comp.sys.amiga.programmer Subject: Re: Functional Programming (Re: Good programmers and assembly language) Message-ID: <7248@harrier.ukc.ac.uk> Date: 8 Apr 91 16:00:34 GMT References: <1523@tronsbox.xei.com> <7235@harrier.ukc.ac.uk> <1991Apr8.005252.8503@neon.Stanford.EDU> Reply-To: mr3@ukc.ac.uk (M.Rizzo) Organization: Computing Lab, University of Kent at Canterbury, UK. Lines: 57 In article <1991Apr8.005252.8503@neon.Stanford.EDU> espie@flamingo.Stanford.EDU (Marc Espie) writes: >In article <7235@harrier.ukc.ac.uk> mr3@ukc.ac.uk (M.Rizzo) writes: >>In article <1523@tronsbox.xei.com> dfrancis@tronsbox.xei.com (Dennis Heffernan) writes: >>>In article <7214@harrier.ukc.ac.uk> mr3@ukc.ac.uk (M.Rizzo) writes: >>>|qsort :: [*] -> [*] >>>|qsort [] = [] >>>|qsort (a:X) = qsort [b|b<-X; b<=a] ++ [a] ++ qsort [b|b<-X; b>a] >>> If learning a high-level language means putting up with gibberish like >>>THAT, I think I'll switch to raw hex instead. >Well, Miranda is not incredibly readable. Don't agree here. Its very easy to understand once you get used to the notation which isn't too difficult to get to grips with, especially if you're familiar with some elemenatary Math notation. The above qsort is much more readable than quick sort in Pascal. It captures the essence of the algorithm and relieves the programmer of having to deal with unimportant implementation details. >How about a nice factorial function ? >fact(n) = n * fact(n-1) >fact(0) = 1 >There are languages around where you can specify it that way, and it will run. This will work in Miranda if you swap the lines around, though the brackets around 0 and n aren't neccessary - spaces will do as well. >There are also languages where you can DO things you wouldn't even think of >doing in assembler or C. Ever heard of lazy languages ? You can define lots >of stuff, the language won't even bother about evaluating them... unless it >NEEDS too. For instance, you can define the list of ALL the primes number, >and do computations with it... Just for the record: there is nothing these languages can DO that assembler can't (follows from Church's thesis). They just make it more convenient and neater. BTW Miranda also uses lazy evaluation and is one of the languages you are talking about. >Maybe quicksort is not always the right algorithm... it almost never is, >in fact. The thing is, it won't take you much longer to rewrite your >sort as a heapsort or anything else. Agreed. Just for the record (again), I was not trying to imply anything about the "right" sorting algorithm. I was just demonstrating the expressive power of very high-level languages and IMHO quick sort is a very nice and easy-to-comprehend example. >As advanced bibliography, the Peyton-Jones' Compiling Functional Languages ... Are you referring to the Prentice-Hall book "Implementation of Functional Programming Languages" by P-J or another book of his ? > Marc (espie@flamingo.stanford.edu) Michael Rizzo