
BASIC as a Haskell DSL (2009) - tel
http://augustss.blogspot.com/search/label/BASIC
======
wyager
Source code and docs:

[http://hackage.haskell.org/package/BASIC-0.1.5.0](http://hackage.haskell.org/package/BASIC-0.1.5.0)

------
mseepgood
Scala BASIC DSL: [http://www.scala-lang.org/old/node/1403](http://www.scala-
lang.org/old/node/1403)

~~~
juliangamble
Some more background to this:

[http://blog.fogus.me/2009/03/26/baysick-a-scala-dsl-
implemen...](http://blog.fogus.me/2009/03/26/baysick-a-scala-dsl-implementing-
basic/)

------
kyberias
I wonder what domain would BASIC be specific with? :)

~~~
acqq
Obvious use of mutable arrays? And making "spaghetti code."

~~~
jacquesm
Very funny. But there are actually quite a few very nice versions of basic
that you could write enormous programs with reasonable structure in, and a
number of those appeared very long ago (For instance, GFA basic on the Atari
ST and BBC Basic for the BBC Micro).

Not that that is in any way relevant to the version of BASIC on display here,
but there was no reason to implement a crappy basic, they could have done it
with a decent version as well. (but that would have been a lot more work).

~~~
acqq
I know that the Goto isn't necessary but I believe that the implementor
demonstrated Gotos exactly to prove that even that can be done in Haskell. The
"decent" constructs were probably easier to implement in Haskell.

I'm personally honestly totally impressed with what the author did because
I've learned a lot, not actually using Haskell myself. It's a good
demonstration of what is possible, especially when the generated code is
shown. I'm one of those that only care for performance, and according to one
comment the generated code seem to be even better than the one produced by
idiomatic Haskell:

"Don Stewart said...

And the assembly we get from GHC with just the obvious recursive
implementation in Haskell,

    
    
        go:
         comisd .LC0(%rip), %xmm5
         jb .L4
         movapd %xmm6, %xmm5
         jmp *(%rbp)
        .L4:
         movsd .LC1(%rip), %xmm0
         movapd %xmm0, %xmm7
         divsd %xmm5, %xmm7
         addsd %xmm0, %xmm5
         addsd %xmm7, %xmm6
         jmp go

"

The one made from the Basic source by Haskell as cited by the article author
is obviously better:

    
    
        LBB1_1: ## _L4
            movsd   LCPI1_0, %xmm2
            movapd  %xmm1, %xmm3
            addsd   %xmm2, %xmm3
            ucomisd LCPI1_1, %xmm3
            divsd   %xmm1, %xmm2
            addsd   %xmm2, %xmm0
            movapd  %xmm3, %xmm1
            jne     LBB1_1  ## _L4
    

So it seems using Basic idioms in Haskell is still a bit more effective than
using the Haskell idioms in Haskell. Or more poignantly "the spaghetti code in
Haskell is faster than the idiomatic Haskell." That was the starting point of
my former comment.

I'd still welcome the comments from the language implementors.

~~~
spion
I think thats the best of both worlds. You can write really nice and clean
code (the default) while still having the ability to "get ugly" (for
performance reasons) if you really need to.

~~~
acqq
Then it seems confirmed that something like Basic in Haskell _is_ actually
useful. Imagine, once when everybody learns Haskell as the first language,
"advanced" books will teach people BASIC. In Haskell. Or maybe the compiler
will get even better.

Still, the educational value of the Basic in Haskell is huge for me. I thank
Augustsson.

