KludgeCode

is Ben Rudgers

Step for Character Ranges in Haskell

One of the side of effects of taking Dan Grossman’s Programming Languages course at Coursera is removing some mental block I’ve had in regard to just loading up and playing with a new language.* Late last week in it was Node.js – just for the sake of a question on StackOverflow – one that got me thinking about Racket’s Htdp2/Universe teachpack. Today it was Haskell based on reading this post on HN over the weekend.

Anyway, I had Learn You a Haskell open to the introduction of lists, and started playing around with the step argument for ranges of ranges of characters:

ghci >['b'..'z']                  -- a range of characters
"bcdefghijklmnopqrstuvwxyz" 
ghci >['a', 'b'..'z']             -- if a is the first character
"abcdefghijklmnopqrstuvwxyz"      -- then it the same as 1?
ghci >['b', 'b'..'z']             -- nope
"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbInterupted  --with Cntrl-c

ghci >['a', 'c'..'z'] -- every other letter.
"acegikmoqsuwy"
ghci >['a', 'd'..'z'] -- every third letter.
"adgjmpsvy"

I think I’m going to like Haskell – it feels like a more expressive SML.

  • I give a great deal of credit to the thought Grossman put into the first exercise in Ruby which essentially created that expectation that learning enough of a language to read and modify some simple code was reasonable.