Since early August, I had forgotten about my plan to learn haskell. Today I refreshed my memory from the docs I read back then, and started writing some very simple programs. Reading a lot of docs and letting it gel for a few months seems to have worked fairly well, I was able to throw this program together in short order, and I think it's not too horrible.

putStrs = putStr.unlines
x s n = unwords $ take n $ repeat s
plot x s = (take (x-1) s) ++ "  " ++ (drop (x+1) s)
f x = truncate(40 + 38 * sin(x / 9))
line = "JOEY HESS" `x` 8 
main = putStrs [ plot x line | x <- map f [1..]]

If you're wondering what it does, the equivilant perl is:

#!/usr/bin/perl -lisubstr($_,39+38*sin++$y/9,2)=$s
for($s='  '||McQ;$_='JOEY HESS 'x8;print){eval$^I}

I suppose both demonstrate features of their language to some extent.


At first I assumed haskell would automatically convert the floating point value coming out of sin and I got a nasty suprise:

    No instance for (Floating Int)
      arising from use of `f' at foo.hs:17:21-26
    Possible fix: add an instance declaration for (Floating Int)

Adding the truncate fixed that, but figuring that out from the above error message and google took longer than figuring out how to write the rest of the program. :-(

discussion