I had been considering Haskell a value-oriented language and had concluded that doing a lot of file system actions would be cumbersome. Dons, put that all to rest:
metaperl: dons - if you are doing a lot of file-system
manipulation, doesnt using a value-oriented language
like Haskell become cumbersome?
metaperl: dons - i mean things like copying files, renaming files, etc
dons: metaperl: hmm, like darcs?
dons: why? you're using a first-class action oriented language too, remember
metaperl didn't think of darcs
dons: so you can string together your manipulting functions in interesting ways
dons: i.e. haskell treats imperative statements as first class citizens
dons: you can pass them to functions, put them in data structures
dons: map over them
dons: > sequence_ $ reverse [readFile "/tmp/x", writeFile "/tmp/y"]
wow. Haskell wins again.
Optional args are not part of the Haskell Way. I have about 20 calls to this function:
for f in path(my.zip).files('*'):
but then I needed to do the same thing but I needed to prepend the date to the file for one particular invocation of this. So, in Python, I simply tacked on an optional argument and used a default value which led to the behavior that the oroginal 20 calls to this function would expect and then I added some code to handle prepending of date:
def archive_zip(my, prepend_date=False):
for f in path(my.zip).files('*'):
today = datetime.date.today()
s = today.strftime("%b-%d-%y")
newfile = "%s-%s" % (s, f)
syscmd = "cd %s; mv %s %s" % (my.archive, f, newfile)
Now, I'm not sure how quickly I could evolve this function in Haskell, but I'm dead curious to know.
This is a placeholder thread for all of the funny things I see in
one of the reasons oo is so good at solving problems is because it's so good at creating them :)
"Ok students, today we are going to learn something different and amazing. It's called purely functional programming... did you notice you entered this room? Sometimes 1 of you came in, other times 3 came through the door? Well, in a functional language, that would be OK, but we would type it like this:
enterDoor :: timeQuanta -> [Student] -> [Student]
I started this out as a post about how a function always took the exact same arguments... ALWAYS... OK now I got it.
"Ok students, you noticed you that dog came in? And then that principle? That's the beauty of FP. Any possible set of inputs MUST be stated up front, so we have to change our funciton again."
Hmm, this didn't go as planned but it's leading somewhere. Bear with me. I'll clean this up sometime... i'm supposed to be working now :)
A type is a set of values. Earlier, I discussed how I had to do programming on something that was no more than a list whose elements were "consed" together via carriage returns:
"item 1\nitem2\nitem 3"
While I did manage to write an implementation of
lines, the Haskell type system is reknowned for forcing programmers to describe their data up front.
But, the Haskell type system did not interpret my string as a list for me.
Sometimes the static typing language just doesn't have the types necessary to express the conditions on code which the programmer would want to express, and sometimes adding those additional types will either spoil type-inference, or make the problem of proving that a program satisfies its types much harder, or even make it outright impossible for the compiler to do for itself.
In reflection, I suppose I could resort to Parsec to produce a list for me.
In working through SJT, I was required to implement
lines. For the first time ever, I managed to break a Haskell program while running it instead of the type checker catching the problem. Feast your eyes on this:
*Main> mylines ts
["dog","cat"*** Exception: Prelude.tail: empty list
As usual, that got me thinking about how I got into the situation. And it hit me, that my main problem is that I had to do programming instead of creating a very strong type and related accessors.
In other words,
lines converts a sequence of lines into a the sequence we call a list.
It seems that I should be able to type a string consisting of carriage return delimeters as a lazy list which returns elements.
Hmm, just brainstorming.
Here I list everything that I will probably never get the time to do, but want to do.
- haskell paste site
- paste.lisp.org has gone down one too many times for me. I think it's time we had our own robust paste tied into lambdabot.
I am happy that I finished Chapter 7 of SJT today. It was a mammoth chapter. It involved a lot of thinking and I am a stronger programmer for having made it.
That being said, I really needed to fight my addiction to perfection. On a hard exercise, I took the liberty of stringing together several prelude functions without (a) learning how they worked or (b) rewriting them myself.
Also, my solutions may not be the most efficient.
But you know what? I'm done with the chapter and I'm better.
If I really wanted to be anal, I would have to rebuild the hardware I'm on for max speed. And then recompile ghc with all the right compiler flags, etc, etc.
DONT SWEAT THE SMALL STUFF!
Chapter 7 in SJT is "Defining functions over lists" --- this is arguably the meat-and-potatoes chapter of the entire book, and it has some great exercises.
However, I was a bit concerned with the given implementation of split because it went over the same part of the list twice:
split :: String -> [Word] split  =  split st = (getWord st) : split (dropSpace (dropWord st))which lead me to examining the source in the Haskell prelude
It looks interesting. So I'm pondering whether to study the entire prelude or continue on with the text.
I think the book is better for me, so that I can learn more of the Haskell system - modules, type classes, infinite lists, monads, algorithm analysis.
It will make me a complete programmer, ready for other interesting articles and exercises and contributions to the Haskell community.
exists right here
... I like how he partitioned the idea of monads into 3 types. I wonder why Cale wrote "Monads as Containers"... was he trying to say that was the only way to look at them? Or must a container always be present? I'll have to ping him on that.