"Thinking in types" or "The mind of a programmer"

Apr 27, 2007 16:38

In a previous post, pozorvlak and I wondered about the differences between the thought processes that goes into writing good static code, and those that go into good dynamic code. We figured that there wasn't a lot out there to help dynamic programmers get the hang of static style thinking, so what follows is a simple little toy example, solved in what I ( Read more... )

thought processes, hacking, typing, haskell

Leave a comment

Re: unfolding ari_rahikkala May 1 2007, 07:19:48 UTC
(gah. Exhaustion and XHTML don't go well together. I deleted an earlier post of mine here, different in the respect that it had some broken italics elements...)

Anonymous parent poster: Your solution is pretty similar to my hacked-up-in-ghci one, except yours uses unfoldr while mine recurses explicitly (I have not yet attained the level of enlightenment where the former feels more natural than the latter):

split _ [] = [[]];
split at xs = let (this, rest) = break (==at) xs in this : if (null rest) then [] else split at (tail rest)

My process to arrive at this went something like...

let split _ [] = [[]]; split at (x:xs) = if (x == at) then

... wait, what do I put in here? I can't think of a way to say "start a list at this element and then when you get to some certain element end the list" that does not involve a call to a different function that I'd have to... no, actually, I wouldn't need to write it after all, I think it's in the Prelude... span? *checks type* ah, yes, that's the right type, except that what I want actually ( ... )

Reply

Re: unfolding totherme May 1 2007, 10:21:22 UTC
(a good example of the loose reasoning used in coding here: When I realised that an assumption of mine was wrong, I immediately went on to fix things so that the assumption would be right without actually thinking of whether it has anything to do with how the code is breaking. In this case it was the right thing, not a surprise in a program this short, but in my experience it's usually *not* the right thing to do when working with code that's even slightly more complex)
That interests me ( ... )

Reply


Leave a comment

Up