Previous Entry Share Next Entry
06:36 pm, 16 Apr 04


I got all confused with that last post. What I was trying to say was:
  1. Human languages pretty much all do the noun-verb thing, and variation in structure is relatively minimal. Programming languages have a pretty small problem domain, but approach it a wide variety of ways.
  2. Human languages have a large lexicon, and programming languages usually don't. The neat thing about Haskell's lexicon is that there's so much abstraction that stuff connects together in all sorts of neat ways, so mastery of the lexicon allows truly succinct expressions of solutions much in the way a large vocabulary allows for shorter sentences. I spotted cool tricks like these while I was reading through the prelude:
    reverse          =  foldl (flip (:)) []
    (That colon is the cons operator, and "flip" takes a function of two arguments and produces the same function with its arguments in the other order.)
    any p            =  or . map p
    all p            =  and . map p
    (all predicate list evaluates to True if the predicate function is true for the whole list. The period is the function composition operator.)</i>

Speaking of language hacks: functional languages often have a problem with reading from files, because the "read" function typically either reads into a buffer, or returns a different string on each call. Haskell's answer?
readFile   :: FilePath -> IO String
It returns a list of chars that is the entire file. A waste of memory? No, because evaluation is lazy: bytes are only read from the file as other parts of the program evaluate those parts of the list.
Unfortunately, it's probably still inefficient because it reads a byte at a time from the file. But it's still neat.