Donald Knuth's Art of Computer Programming Series uses his own procedural assembly languaged called mix. Now, the question becomes: should Knuth have used a functional language to describe his algorihtms? Should TeX have been written in a functional language?
Computers have a procedural architecture. Do the roots of computation imply anything about the best branches?
In an interview with Autrijus Tang, we hear Autriju making several strong statements in support of Haskell:
IN THE LANGUAGE SPECTRUM
Haskell is faster than C++, more concise than Perl, more regular than Python, more flexible than Ruby, more typeful than C#, more robust than Java, and has absolutely nothing in common with PHP.
ECONOMY AND POWER
Most languages require you to pay a "language tax": code that does nothing with the main algorithm, placed there only to make the computer happy.
Thus there is a threshold of refactoring: if introducing a new class or a new function costs five lines, programmers are encouraged to copy-and-paste four lines over and over again instead of abstracting them out, even with help from a good refactoring browser.
On the other end of spectrum, we often shy away from abstracting huge legacy code because we are afraid of breaking the complex interplay of flow control and global and mutable variables. Besides, the paths leading to common targets of refactoring--those Design Patterns--are often non-obvious.
Because Haskell makes all side effects explicit, code can be refactored in a safe and automatic way. Indeed, you can ask a bot on #haskell to turn programs to its most abstracted form for you. Haskell also encourages you to shape the language to fit your problem domain, so the program often reads out like a runnable specification.
-- 2 oranges make 8 ounces of juice
ounces 8 = Oranges 2
-- a 32.oz non-organic orange juice costs 4.55 at Jamba Juice
ounces 32 = Cost 4.55
-- at retail price, I get 72 organic oranges for 10.00
-- which means 7.2 oranges for 1.00
-- which means 15 cents per orange
-- which means 30 cents for 8 ounces
-- which means 1.20 for 32 ounces
-- which means 3.35 cheaper than Jamba Juice and organic produce
-- I can get much cheaper prices on oranges if I buy in bulk
I was in a job interview for a Perl position and I volunteered some information about learning Haskell in my freetime since it has improved my Perl programming so much.
Then my boss asked me this: "what advantage does programming in Haskell have over Java or C++. They have strong typing don't they"
And my answer was: "they don't have type inferencing" --- but is not advantage, only something different it has. What would you say are the advantages of Haskell over Java or C++?
I noticed some discussion on #haskell about darcs needing a new maintainer. Should I look at other options for version control that are better maintained and supported or is this just rumours about darcs? I hope they are.
I recently found a fascinating job but was dismayed when they said they expected people to use HTML::Mason (a jsp/could-fusion/php-like embedded HTML generator for Perl) and MySQL. Instead of verbalizing my dismay, I decided to finally write the ultimate document on why inline HTML generation and MySQL are Bad Choices ... that's right
In doing so,I had to be tongue in cheek about one thing. I value decoupled program elements and that's why I like Haskell... it gives one maximum ability to define small pieces and maximum operators for flexible composition, allowing one to form complex computation strategies from small, well-tested, well-understood pieces.
Of course, the problem becomes: decoupling means that you have weaker encapsulation.
So we arrive at the battle of the buzzwords... which is better: decoupled program elements or encapsulated ones?
-- bills paid on the 15th of the month
on 15 = [100.00,110.00,60.00,52.00,100.00,150.00,450.00,240.00,68.45]
-- bills paid on the 30th of the month
on 30 = [300.00,75.00,150.00,125.00,125.00,150.00,100.00]
-- total paid on 15th of month
s 15 = sum (on 15)
-- total paid on 30th of month
s 30 = sum (on 15)
-- total monthly bills
tot = (s 15) + (s 30)
I was staring at chapter 10 in SJT's text and realized that each time he created a more general function, it was done by creating a function which worked on any type whereas the original function was "hardcoded" to process only the type of data.
I took a day off work to get an eye exam and then headed to Jamba Juice to get 4 32-oz containers of fresh-squeezed juice. I headed home, ready to continue my Haskell explorations.
For some reason, I decided to take just a few minutes to try to get my old laptop ip masquerading to my main machine, since I had never managed this before.
Well, boy was that a mistake. I tried guarddog and guidedog. I tried google and IRC. I tried man route. I tried shorewall. 8 hours later:
- no better at Haskell
- no ip masquerading
- severely frustrated
The lesson: pick your battles. Linux is an experimenters toolbox. It is very free and open and configurable and you will often have to do research to get anything done (unlike Windows). This is great at times but tempting at others.
I need to realize that I am a software developer who wants to transition from Perl to Haskell and stay focused on that. I will never be as good at networking as the sysadmins at work and I dont need to waste my time in such efforts.
had I bought a wireless bridge like linksys tech support said, or had I tried out the wireless card I bought, I would have had an easy and predictable path through unknown territory.
I havent even mentioned that a normal ethernet cable doesnt work. If it had not been for the phone tech who came out to fix my "phone problem" (ok, ok, sorry my laundry disconnected my phone and it was buried under 4 feet of laundry so I never noticed it), ... anyway. the phone tech saw I was using Linux and told me about his 4-processor Itanium and how Microsoft charges 2700 for its Windows version for this machine. He noticed the wire running between my machiens and told me I needed something called a crossover cable... yet another unknown thing...
So: pick your battles, stick to your guns and cherish your free time for what you need to get done... even if that means iconifying your IRC client, being a bit dumb about a bunch of things not related to your goal... and I didnt mention the lady who I told I wanted a vegetarian plate at the restauranet. I lift up the scrambled egg and there staring at me if roasted beef... she tried to scrape it out of the bown and give it back to me.... and yes, there were still beef chunks in there after her attempt to save some dollars... and of course I would've been urling my guts out for hours had this vegetarian body accidentally taken in that garbage.
Rule #2: dont play in the fire unless you dont mind getting burnt. Pick vegetarian restaurants if you are a vegetarian. If they serve meat at all, then stay the hell out... unless you like carcass grease mixed in with your veggies. Or better yet, cook for yourself so you arent wondering what the cook did with his hands, or what tasty ingredients they added that due nothing but constipate and poision the body (ie. table salt, distilled vinegar, white flour, etc etc).
I was trying to work problem 7.26 in Simon Thompson's "Craft of Functional Programming":
given a STRING search for SEARCH and replace with REPLACE
Now, having fallen in love with the ability to give top-down specs for things in Haskell, I tried this for starters:
substr search replace input = pre ++ sub ++ post
meaning given an input string, we have the unaltered pre and post parts and a conditionally altered sub part.
But I could not take this top-down description further without searching the string numerous times. John Goerzen was nice enough to come up with this solution for me:
I'd recurse over the string, dropping the first character on
then I'd compare the first (length search) characters to (search)
If they're the same, I'd return (replace ++ xs)
otherwise return x:self xs
subst search@(s:ss) replace input@(i:is)
| chunkSearch search input = replace ++ (drop (length search) input)
| otherwise = i : subst search replace is
-- presumes length a < length b
chunkSearch a b = a == take (length a) b
Well, I like this solution, but I'm a bit worried that my top-down approach fell through on me. It's interesting how he simply builds the
pre part on the fly and then pastes the
post part in with