[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: another take on hackers and painters




> Date: Tue, 20 May 2003 19:10:56 +0200 (CEST)
> From: Jakub Travnik <J.Travnik@sh.cvut.cz>
> 
> From: Michael Vanier <mvanier@cs.caltech.edu>
> 
> > 
> > I can't say I agree with your views on static typing, although many on this
> > list will.  Have you ever used a really *nice* static type system like in
> > ocaml or haskell?  They're not perfect, but they're miles ahead of what
> > most people think of when they think "static typing".  Here is quicksort in
> > haskell:
> > 
> >     qsort :: [Int] -> Int
> >     qsort [] = []
> >     qsort (x : xs) = qsort [ y | y <- xs, y <= x ]
> >                      ++ [x] ++ qsort [ y | y <- xs, y > x ]
> > 
> > Beautiful enough for ya? ;-)
> 
> Very nice example of static typing! ;-)
> 
> See, there is an error. The error is in the type information
> _only_. If you did not write type information, all would be correct
> (I know that in this case this is not needed in Haskell). Of course,
> compiler will catch the error, but in the language with dynamic typing
> there could be no such error.
> 
> 
> Jakub Travnik
> jabber://jtra@jabber.com
> 

That's the great thing about this list -- you can't slip anything past
anyone ;-)

OK, revision two:

    qsort :: [Int] -> [Int]
    qsort [] = []
    qsort (x : xs) = qsort [ y | y <- xs, y <= x ]
                     ++ [x] ++ qsort [ y | y <- xs, y > x ]

This of course only works with a list of integers, but if you supply a
comparison function as well you can make it work with a list of any
specific type.

Mike