Archive for June, 2010

My First Haskell Question

June 22, 2010

This is a technical admission that I don’t really know what I’m doing in the Haskell programming language, but there are some successes — I’d welcome any feedback, positive or negative, since I’m learning as I go here…

So I installed Haskell Platform for Windows no problem; learning Haskell is not a problem per se — there are tutorials, and the wikibook but I can’t find what I want to know… (I may have to revise that — see update after the break)  I may want to read the “How to…” by Wash. U of St. Louis students, or perhaps Write Yourself a Scheme in 48 Hours.  Also, of note is Real World Haskell, the book online…

But having not done those things, here’s what I tried:

data BUEntry = FileSpec String
    | WCFiles String
    | Folder String
  deriving (Eq, Ord, Show)

A “backup entry” — I’m trying to write a program to ‘backup’ files (simply by copying from one folder to another), for now… — either a “FileSpec”: a filename, including path; “WCFiles”: wildcard files (a folder name and some wildcard spec — in common format); or a “Folder”, indicated by the trailing backslash (this means copy the entire directory).

So far, so good.  Now I want to “convert” a BUEntry to a list of strings — possibly only one.

getFileList :: BUEntry -> [String]
getFileList (FileSpec s) = [s]

So this is the signature of the function to do so, as well as the first, for a “simple” FileSpec, which returns a list of this only…

Working on “getFileList (WCFiles wc) = …” I first have to extract the path….

well, maybe it would be easier to start with “getFileList (Folder f) = …”  I found the function getDirectoryContents in the Directory module.

import Directory

getFileList (Folder f) = let files = getDirectoryContents(f)
                         in files

But of course:

Couldn't match expected type `[String]'
      against inferred type `IO [FilePath]'

So what is the type “IO [FilePath]” ?? Is that a monad thingy?

Five hours later, I’ve concluded that, yes, indeed it is.  From the students “How to” (see above), I read about astronauts, then “All About Monads.”


Haskell in the News

June 15, 2010

This is a tech update that doesn’t report a whole lot of progress, but some interesting links.

I need to read SD Times more often, methinks.  Today I read thisLLVM is the compiler infrastructure of the iPhone SDK (will it now be called iOS SDK?).  Then I found this, looking for details and a quote.  From the abstract:

Haskell as implemented by GHC was found to map remarkably well onto the LLVM Assembly language,although some new approaches were required.

Instructions here.

[That’s six links in two paragraphs (plus two to S/W Dev Times) – the Wikipedia article, the LLVM website itself, a story describing the uses by XCode, the Apple website; then the reddit article pointing to David Terei’s thesis, and finally, instructions on setting up LLVM-GHC.]

So now for my status: I’ve been meaning to get back to Haskell programming for a while now, but I’ve been stymied by other things —
for the record, I have three or more projects “in the works” (at least thought of, if not actively developing):

  • I’ve taken my Clojure code to work on SRAT and added an AWT UI, plus I’m loading state via Dan Larkin’s JSON library— I realize now that I haven’t posted anything about this work.  I’ll have to remedy that, also.
  • besides the Haskell for “backup” (which I’ll describe soon), I’m reading the OCaml beginners’ mailing list and I’m coding in Jython trying to run IE via j-Interop, but having problems w/ passing an (empty) string array… or some such, I’m not sure what the issue is with calling the DispHTMLDocument interface method frames [believe it or not, I can’t find a link I want to include here — to the ‘generic’ inteface defn. as found in the IDL].
  • I want to do a calendar app for myself (a two-week wide table), with Julian Date and repeating events (like Christmas and Thanksgiving)…  prob. in Haskell, for the practice, but
  • I’d also like to do something with J, which I don’t know right now…
  • I am thinking that a Sudoku app in all the languages I can now code in (for “comparison” — to communicate the boad via a shared file format)
    [my current list is Jython, Clojure, Java (perhaps redundant, given the previous two), C++ maybe, Haskell, … ?? SmallTalk, (other suggestions? Ruby?), Javascript, [J]…

A little ambitious, but if I can just get to my Haskell problems first…

  • and I’m interested in writing an iPhone app (is that now passé?)
  • and I am trying to get Linux running on an old iBook — having trouble w/ wireless there, too…


June 4, 2010

This is going to be a “religious” post, so if you’re looking for tech, check back later — I’m trying to get “one simple thing” working in Haskell, then I’ll write that report.

I’ve heard say a coincidence is when God decides to act and remain anonymous…

Wednesday my wife and I had supper with a friend (yes, my little boy was there, too, but he was very well behaved).
She asked a question of my wife (I only got the details later), via e-mail prior, but the gist of it is (and I hope I’m being accurate), “Why do I have [this] longing?  Isn’t God supposed to meet all my needs?”  That’s not quite it, because writing it that way sounds accusatory, and she wasn’t (yet) thinking that, I don’t believe.

Closer to the real question is this: Why am I lonely?  And what can/should I do about that?

Then yesterday, I read this post on the blog Stuff Christians Like.  In short, he writes that God cares about loneliness.

To which, my cynical side replies, “Great, but that doesn’t put another person here.”  But that’s not being fair either.  The question is more to the point, “what can I do about it??”  And that has always been the million dollar question.

… giving it another hour of thought, I think I missed something: sometimes, it does matter, just knowing that God cares, and the blog entry makes the point that this is one of God’s first concerns (see Gen. 2).  Our church has made a point to emphasize that Christianity is meant to be lived out, in community; not in isolation like our culture so often implies.

2ndly, and this is to those who are lonely: I care, and other Christians (not all, would that it were so); but one cure I know for these situations is to get involved with other people.  Zig Ziglar says, “you can get everything you want in life if you will just help enough other people get what they want.”  And I believe there is some truth to that — moreso the more I dwell on it.  The more other-focused we are, the less time we have for our own problems.  (The cute plaque with two puppies says, “If you want a friend, be a friend.”  Which also sounds trite, but there is a truth there…)

Now I’m going to begin addressing myself (you can listen if you want, but know that I am not preaching at you — I can’t, since I don’t know anyone’s situation but my own…).  I have long thought about Michael Card’s song “Know You in the Now” on the album Present Reality.  “Lord, I long to see Your presence in reality, but I don’t know how… let me know You in the Now.”  Recently, separate from the preceding, I’ve come to understand: the way we Christians see Our Lord in this world, and the only way others will ever see Him, is through the lives of fellow Christians.  But the reciprocal of that is: the only way other people will ever see Jesus Christ is through my life. That puts some responsibility on me to live in such a way that others see The Light in me.  (Not a heavy burden, because it is only thru God at work in my life that it can happen — it is His responsibility, I only need to get out of the way and be a conduit of His Love and Life.)  I can’t now go in to all that, but suffice it to say that talking about it isn’t right either — “the Word became flesh,” and so, too, this truth must be lived out, not just spoken.

This has been just a short post — as always — there is more unsaid than I can ever find time to write; if you have an idea, leave a comment and I may respond to it, in time…