BASIC as a Haskell DSL (2009)
augustss.blogspot.com
augustss.blogspot.com
http://blog.fogus.me/2009/03/26/baysick-a-scala-dsl-implemen...
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).
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.
main :: IO ()
main = do
let go :: Double -> Double -> Double
go !i !s
| i < 100000000 = go (i+1) (s + 1/i)
| otherwise = s
printf "Almost infinity is %g\n" (go 1 0)
Inner loop assembly: LBB0_4: ## %c3Sk
movaps %xmm3, %xmm0
divsd %xmm1, %xmm0
addsd %xmm3, %xmm1
ucomisd %xmm1, %xmm4
addsd %xmm2, %xmm0
movaps %xmm0, %xmm2
ja LBB0_4
jmp LBB0_2Still, the educational value of the Basic in Haskell is huge for me. I thank Augustsson.