Friday, February 06, 2009

Regression

They say that as you get older you regress back towards childhood. So I present you with today's Haskell program (the idea shamelessly stolen from JoshTriplett from #haskell on IRC):
import BASIC

main = runBASIC $ do

    10 LET X =: 1
    20 PRINT "Hello BASIC world!"
    30 LET X =: X + 1
    40 IF X <> 11 THEN 20
    50 END
Yes, it runs. (I'm sorry about the =: instead of =, but some things are just too wired into Haskell to change.)

13 comments:

  1. Nice. I guess this is based on PrintfType-like type class trickery and doesn't reject invalid basic programs until runtime, right?

    ReplyDelete
  2. It can go wrong in many ways at runtime, just like real BASIC. :)

    ReplyDelete
  3. Does it run if we reorder the statements? Or are the line numbers just for show? In other words, does this work?

    50 END
    20 PRINT "Hello BASIC world!"
    30 LET X =: X + 1
    40 IF X <> 11 THEN 20
    10 LET X =: 1

    ReplyDelete
  4. You can reorder the statements if you like.

    ReplyDelete
  5. I take it there is a limit on the available variable names? Not that this is ahistorical: Commodore BASIC ignored all but the first two letters, for example; but allowing arbitrary names would be a challenge.

    ReplyDelete
  6. Quiz: Dartmouth BASIC has a limit of 286 variables.

    ReplyDelete
  7. Lennart - this made my day. I can smell the food in my mother's kitchen.

    ReplyDelete
  8. Hey, this was my idea! And Josh also has a working implementation!

    It's cool that you went ahead and did an implementation as well, and cool that you gave Josh credit. However, it would also have been nice to give us a little time to get ours out first. We had big 1 April plans for it.

    I hereby sentence you to write a few thousand lines of HBASIC. :-)

    ReplyDelete
  9. PO8: I'm sorry, I didn't know it was your idea. Nor that you had plans.

    My apologies.

    ReplyDelete
  10. It's all good fun. I mostly just wanted to clarify the situation. Josh and I will keep poking at it also---we're already making our next plans.

    It looks like you have the HBASIC language pretty clean at this point with your implementation. Will you post the source code soon?

    ReplyDelete
  11. Nice. I guess this is based on PrintfType-like type class trickery and doesn't reject invalid basic programs until runtime, right?cheap electronics

    ReplyDelete