Saturday, April 30, 2011

Limits, colimits, and (a very limited look at) their usefulness in programming

Teacher, author and professor extraordinaire (disclaimer: I'm not being sarcastic, I really highly respect this man) Robert Harper posted a high-flying, chock-full of much more information that was used to write-it article on his blog: The Point of Laziness

In it, he tries to once more expound on why the Haskell programming language is unfit for teaching introductory FP. Once more, he has so much to say on the matter, that he winds up only telling that he has a lot to say. Pretty much, if you understand his arguments, you already know them, but fortunately, there are other readers who comment, and draw out more info to better understand what he is particularly speaking about.

Jeremy Gibbons, in a thankfully reliable style, saved the day, with this lovely sum-up on reddit:
"Due to the way Haskell allows ⊥/'undefined' to inhabit all types, the projection/injection functions that
define how a product/sum type behaves are not sufficient to uniquely identify the value of interest." (my interpretation; please castigate me, and not him.

It's slow-going, but learning is happening...I think.

Wednesday, June 23, 2010

A Half-Minute Introduction to Functional and Object-Oriented Programming

Okay, I'm not going to be quite so ambitious as to explain everything about both paradigms, just one example that highlights what a major difference is and why it exists.

Today's example: "object" state.

Imagine a small Post-It pad as your memory, with, say, a number "2" written on it. In fact, let's be more "ambitious," and imagine a mini-clipboard, with four post-it notes on the back:


"John"                "Smith" 

Yes                   2       

Now, imagine tearing off the "2", writing a "3" on a new note, and sticking the new one in the place of the "2".
To an OOP person, you've just changed the state of an object. To an FP person, you just changed which state the object refers to. The OOP person maintains continuity with the object. The FP person keeps continuity with the values associated with an object. To the OOP person, it's the same object, just with different (new) parts. To the FP person, it's a different object, because it has different (new) parts (it just has the same name as the original object).

It's kind of like marriage: you're still you (OO), you're just now the same as you used to be (F)...

Monday, May 24, 2010

Dabbling in incremental folds



    I was playing around coding up programs for Project Euler, when I noticed that I was 1) using an old stand-by function, to add up the digits in a big number; and 2) I was coding it up in a way that echoes up other functions I’ve done, such as the ever-popular “chunk”; 3) I was not coding it up in the semi-unrolled-in-another-dimension form of “map snd . takeWhile (p.fst) . iterate (\(old, pair) -> (new, different pair) $ start” that I also use for that kind of problem, but in the “let (intermediate, pair) = auxiliaryFunction argument in finalProcessing intermediate (recursiveCallOn pair” format. I asked about it on #haskell - hands down, the best resource for help on all things CS-ish EVAR! - when for some reason my brain zigged instead of zagged, and I recalled my Internet “colleague” (make no dispute: the quotes are there because I have no more qualification to be this man’s colleague than I do Stephen Hawking) Sean Leather. Specifically, his blog post http://splonderzoek.blogspot.com/2009/04/latest-on-incremental-fold-and.html  where he speaks writes some more about incremental folds, and like a corny Windows 7 commercial, it hit me: I’ve been writing (and re-writing) incremental folds!

    I find this to be a big deal, if only because I have finally hit the level where instead of just reading about all of these useful high-brain-power techniques, I have caught myself using one - yes! I may not be the sharpest tool in the shed (see: Cletus), but love it all, I Am Trainable!
So, knowing a good thing when I see one, I immediately...well, I immediately got back to doing the day job that I’m really supposed to do, instead of goofing off, then I spent some time playing around on IRC, but that very day, I went back to re-read about incremental folds, and how what I was doing fit all into it. Chalk one up for goofing around on the Internet!

Saturday, November 21, 2009

Abstractions Always Leak - DUH!

I was lurking in my favorite IRC channel today, and not-so-calmly
read as a fellow user blathered on about wanting to provide useful
exercises to help inculcate a better eye for abstraction. Now, while
as explained in this form, I see no problem with this, one of the
other denizens of the channel raised a minor objection to the idea
as being in a way, the opposite of abstraction, to which the original
fellow replied with how it wasn't, since "abstractions leak." Now,
I know for a fact that this person is miles ahead of me in every
positive way to measure computer skill, and better off in many other
ways not relating directly to said skill (i.e., I'm sure the person is
younger, fitter physically, and likely more handsome than I).
However, there is one place where I have him beat - this is my blog
- and I'm going to unfairly exploit my tiny advantage as far as
possible, starting with reiterating my title:

Abstractions Always Leak - DUH!

First off, I want to make sure I'm being clear: I'm not trying
to insinuate that this fellow is any less knowledgeable than I am;
I think I made it clear that he is miles ahead of me in CS
knowledge, technical ability, scholastic achievement, academic
talent and industrial usefulness. I'm just using his remarks
completely out of context as a means to spout off on a topic
only tangentially relevant to his remarks, and utterly underestimating
his understanding of the topic. Remember, I've already stated:
I'm the dumb one in the line-up. Also, once again: this is my blog.
His is much clearer, relevant, enlightening and fun to read.

Okay, now that I've wasted everyone's time with all of my caveats,
let's go back to my original point: abstractions. They leak. Duh.
To start, abstractions are metaphors. They are encoded means of
make-believe and pretend. They are "what-if" in software form.
As such, they are meant to go so far in the world of "let's pretend",
and no farther. Unfortunately, most of the software industry is
based on folks who don't know what they want in software, and
are at times talented enough to craft some that works well enough
at a task that other people are willing to pay for its use. Part of the
fun of Computer Science (yes, yes, it isn't really about computers
as such, but what can be done with one) is finding out how far we
can push the abstraction and when it "leaks", how does it leak,
and why. The most important part about finding where the leak
begins in that we can put up a nice friendly sign and warn people
"here there be Monsters!", i.e. "Just (Don't) Do It". Those are the
two most important things to know about an abstraction, or
a metaphor in general, how it applies, and how it doesn't. When
you tell someone "it's raining cats and dogs," you have to know
stepping in a poodle is a joke, otherwise it isn't funny, except
to others laughing at you. Even then, it isn't really that funny, 'cause
you'd have to be an alien, or a Turing Test-flunking computer not
to recognize that old joke.

But I digress.

So, I guess there are three main points to a metaphor, what's
the comparison between, how does it hold, and where does it leak.
Then you can figure out how you can rely on it to give you good
answers about the first thing, or on something else entirely that
uses a useful characteristic.

Just watch out for those leaks. You don't want to step in a schnauzer.

Thursday, August 20, 2009

Autodidacts, Stand Up and Cheer!

For reasons unknown, but gratefully accepted, MIT has placed almost all of its curruculua on the Web.

Now, those folks that don't have the smarts - or the fat wallet! - for MIT can see what they're missing. Plus, those who live for self-study and self-improvement can follow along at their leisure!

While I have no solid idea why they did this, I have a glimmer of a possibility: whenever I can afford it, I'm going to give MIT $100 a month. Granted, $1200 a year isn't going to get my name on a building, but I can rest assured that the folks that set up MIT's OCW site aren't going to be moping in their offices after ten years, wondering if they "ever made a difference in the world".

As an online writer I read has also commented, this move will also start to show up all those other colleges, that wish they had the competence to stand in MIT's company.

In the meanwhile, I'm going to see what those smarties in MA are being taught, but without forking over the thousands to feed all of that ivy...

Saturday, April 4, 2009

Pet the Nice Doggerrel

When either I, or one of my HS/college buddies were working our card skills - and big egos - out, we had a little saying, "I'm going down fast, but I'm miles above you." Usually, such boasting would be promptly followed by getting the needed contract exactly, or in my case, more likely, missing said contract by a hand. Anyway, I was "in a mood", so I fleshed out the boast into a little ditty, so for posterity's sake, and your perusal, here it goes:

"I'm going down Fast, but I'm miles above you.
I'm going down Hard, but it's okay, I'm tough.
It's not much comfort that you'll land before me,
It's not much comfort - but it's good enough."

Saturday, November 1, 2008

What the World Needs Now is...Jealousy?

Yes - what the world needs now now (and then, but mostly now) is more jealousy. Why would I say something irresponsible and nutty like that? Well, aside from its being true,  its effects will benefit all mankind, except for busybodies and parasites. Here, let me nake my case - first off, step thro' my looking glass, and see what jealousy looks like in my world.

Jealousy ( \JEH-lə-sē\) is defined thus: 1 : a jealous disposition, attitude, or feeling; 2 : zealous vigilance. Ooh, I like that second one - zealous vigilance. You may have guessed, but not known that jealous and zealous are relaated. In fact, they're the same word, just "tweaked" a little through Middle French for that coolest of letters, the 'j'. My own twist on the definition may make my own prejudices more clear: Jealousy is the deep passion a person feels for that which belongs to that person. Jealousy is the desire you feel for that which is yours because it is yours. It is patriotism on the personal level. A modern world leader once remarked in a disgust in any person "who could say they love their country, and hate their government." A strange sentiment for someone from the Central Southern US, a region well-known for jingoistic cheerleading for "America" - or the local school football team, depending on the time of year you ask (not trying to be insulting here - almost all of my family lives in "the South").

Anyway, to me, jealousy means that you hold your things and people in high regard, not because they're better than anyone else, more virtuous, richer, prettier or more powerful. Jealousy means you love what's yours because it's yours, or rather, because you are theirs. Jealousy also means you don't let your object of passion go off in a state of abandonment. If it's yours, you take care of it, and keep it from molestation by foreign hands - foreign in this sense being anyone who shouldn't be there, including greedy cousins with too much of a sweet tooth...but I digress.

Jealosuy isn't only  accusing someone of falsely seeking to betray you. Jealousy is about looking to give the best, and to be the best, to those you love. Now, is that something the world could use more of, or what?