
Writing A Lisp Interpreter In Haskell - llambda
http://www.defmacro.org/ramblings/lisp-in-haskell.html
======
dizzystar
Not sure if you've seen this one:

[http://en.wikibooks.org/wiki/Write_Yourself_a_Scheme_in_48_H...](http://en.wikibooks.org/wiki/Write_Yourself_a_Scheme_in_48_Hours)

I haven't done it, but I hear its excellent.

~~~
tikhonj
This was how I learned Haskell. I rather liked it.

That said, looking back, I'm not sure it encourages the best coding style or
the best idioms. It's perfect for getting your head around the paradigm
though!

I'm currently writing an analogous tutorial for implementing Prolog in
Haskell, but it's on a bit of a hiatus thanks to some school and research
related deadlines coming up. Hopefully people are interested in something like
that :).

Interestingly enough, the Prolog interpreter is actually shorter than the
simple Scheme one--largely because we can take advantage of the list monad for
the backtracking. I think it's still a very cool exercise.

~~~
X6MW3aQrZU5VKkz
I would be _very_ interested in seeing a tutorial detailing how to implement
Prolog in Haskell!

~~~
exDM69
Not really a tutorial and not really Prolog, but here's an interpreter for a
logic programming language written in Haskell:
<https://github.com/rikusalminen/slolog>

I wrote it as a project work in an Artificial Intelligence class. It very
closely resembles the logic programming language implemented in "Structure and
Interpretation of Computer Programs".

I'm sorry there isn't any documentation for it.

Here's a little example of what it looks like, from examples/royalfamily.slo:

(siblings ?x ?y) <\- (parent ?x ?parent) & (parent ?y ?parent)

(grandparent ?x ?y) <\- (parent ?x ?z) & (parent ?z ?y)

(cousins ?x ?y) <\- (grandparent ?x ?gp) & (grandparent ?y ?gp) & !(siblings
?x ?y)

------
dllthomas
Note that this is from 2006. "There hasn't been much Haskell-related work in
[web applications]" is false, now.

Very cool read, though.

------
JoshTriplett
For a practical version for production usage, I've found husk-scheme
(<https://github.com/justinethier/husk-scheme>) quite good.

~~~
fogus
I like Husk very much. I used its TCO/K approach for my own little hobby Lisp.
Great fun.

------
Erwin
Interesting that despite having what looks to me like Haskell and CL
expertise, Slava's RethinkDB (various article describe as a "founder") seems
to be written in C++.

What do Haskell or CL implementation lack to be competitive with good old C++
there?

~~~
ghc
When writing a database, performance is extremely important. Languages like
C++ give you manual control of the computer's resources, which means you can
count on predictable performance and memory management. Why is this important?
All of your database code must be written with the performance characteristics
of your data structures in mind. You need to know how long certain operations
or memory swaps will take so that you can optimize data throughput.

While CL and Haskell can be extremely fast and even outperform C++ in certain
situations, the lack of manual resource management makes them ill suited to
writing a database system. There are few, if any, applications where this
matters so much.

~~~
capisce
Why can't we have the expressiveness of CL or Haskell with the performance of
C++?

~~~
jeremiep
We do, its called the D programming language.

~~~
Peaker

      map (head &&& length) . sort . group
      
      filterM (const [True, False])
    

Can you show how you implement these in D?

If you want, I can explain these or give other examples of expressiveness I
don't think you'll find in D.

~~~
orlandu63
I think you mean group . sort

~~~
Peaker
Oops, quick-typing on my phone can have problematic results :-)

------
dschiptsov
This is, of course, a narcissistic nonsense.

A primitive arithmetic interpreter and the set primitive (why?) is not even
close to what Lisp is.

Lisp _is not_ just a prefix notation with parenthesis. It _begins_ with the
notion that code is data - the list structure _and_ that everything is a
symbol, a reference _and_ that a value has a type, not a variable, which,
_together_ , gives us macros for free.

An implementation of a prefix-notation calculator? Well. It is less than one
screen of Scheme code, and is a part of one lecture of freshman's CS61A
course.

btw, people who have seen Scheme interpreter from SICP and capable to
appreciate its beauty and elegance (structure, clarity, compactness) would
never try to do something like that.)

~~~
phaet0n
Parenthetically speaking, are you aware of the issue with your parentheses?

