Hacker News new | past | comments | ask | show | jobs | submit login
Hasp: An S-Expression to Haskell Compiler (york.ac.uk)
79 points by kruhft on Feb 25, 2012 | hide | past | favorite | 23 comments



Glad to see another attempt at this righteous marriage. The piping approach is very tasteful.

I tried to get this working with Racket (on osx) but hit too many blocks and ended up going with Gambit, which works well so far.


Compare this with Liskell (Haskell semantics with Lisp syntax): http://www.liskell.org/

With both Hasp and Liskell, one writes code that is indistinguishable from S-expressions. In fact, they are S-expressions. I don't doubt that Haskell has things that Lisp doesn't and that Lispers should learn from, but this is another example of what Paul Graham said, that adding Lisp-style macros to any language will only result in another dialect of Lisp.


I'm sorry but this is just ridiculous. Just because it looks like Lisp (i.e., the syntax is s-exprs) doesn't make it Lisp.

Let's count important features of Lisp beyond the fact that it's functional:

- Dynamically typed

- Unsafe

- Eagerly evaluated

- Syntax is s-expr AST

Important features of Hasp/Liskell:

- Statically typed

- Type classes

- Side effects enforced by monads

- Lazy evaluated

- Syntax is s-expr AST

Congratulations, they have one major similarity. If anything Haskell is a dialect of ML, not LISP. I know no one who isn't a PL grad student (guilty) has ever even heard of ML, but it's helpful to look into the history of PL before you start making uninformed statements which basically amount to, "all functional languages are LISP."

P.S.

All functional languages are syntactic suger on λ-calculus.


"Syntactic sugar on the lambda calculus" is just silly, really. I wish people would stop saying this. It's like saying imperative languages are syntactic sugar on Turing Machines.

This is a bit of a pet peeve for me, really. It seems like an unnecessary pithy dismissal of computation theory.


I disagree, it's not like saying "imperative languages are syntactic sugar on Turing Machines" at all.

Haskell compilers generally compile in the following way:

text -> tokens -> AST -> lambda calculus variant -> abstract functional machine code -> imperative IR -> machine code

the AST to lambda calculus variant step is a single step. It takes the Haskell representation of the lambda calculus and outputs lambda calculus.

Contrast this with an imperative compilation:

text -> tokens -> AST -> imperative IR -> machine code

The imperative IR may be LLVM IR. LLVM IR is almost a first order functional programming language, it is certainly not machine code for a turing machine. So imperative languages are not syntactic sugar of a turing machine, there is no desugaring step in the pipeline (except maybe when building the AST).


And what of Lisp, of which most dialects have mutable state? If a Lisp compiler would convert to genuine λ-calculus it would be as large a step as it would for C.


If you would re-read my comment, you'll find that I didn't actually say I agree that all functional languages are syntactically sweetened lambda calculus, though I certainly said Haskell was.

My point was that although there are functional languages that are syntactic sugar over the lambda calculus, I don't know of any imperative languages (and in fact it would not make sense to design an imperative language) that is syntactic sugar over turing machine code.

I should have made my position clearer. I do agree that compiling any non-pure functional language via lambda calculus is a fruitless endeavor.


Especially since they aren't. GHC Haskell, for example, is essentially syntactic sugar for System FC, not λ-calculus.


And system FC is... a polymorphically typed λ-calculus.


Possibly we just a have a different idea of what a lambda calculus is: I was thinking of Church's untyped lambda calculus, which is a much weirder beast than System FC.


Even if you restrict lambda calculus to mean untyped lambda calculus, it's common practice to discard the types once type-checking has completed and continue the compilation without them.


That was a joke -- calling all functional languages syntactic sugar on λ-calculus is just as ridiculous as calling everything with S-expressions lisp. Sorry, sarcasm doesn't translate well over the Internet.


> I know no one who isn't a PL grad student (guilty) has ever even heard of ML

I am not a PL grad student. I have heard of ML. These days I imagine many programmers have heard of ML and Haskell.


Neither am I, though I confess to hanging out with a couple of them, arguing about language design. We used to argue about religion, but programming languages are more objective and just as contentious.


>I have heard of ML.

Specifically F# which is based on OCaml which is based on ML. if F# succeeds "int the wild" I'm guessing a lot more developers will hear about ML.


Is Typed Racket not Lisp? Most Lisps support lazy eval through macros and lambda.


He also calls Lisp "unsafe", and "LISP". Not good signs.


I was imitating the original poster by extrapolating large claims from small differences. I work on Racket. What I really meant is that side effects are not predominantly corralled using monads, but this is not a technical discussion.


Alright, cheers! :-)


I don't know, is it? Are there any specific features that we can point to and say -- "that's a Lisp" and "That's not a Lisp." Or is categorization instead primarily dependent on pedigree? If so, why do we care? What usefulness is this distinction aside from pedagogical purposes?


The author offers his own comparison with Liskell:

http://www-student.cs.york.ac.uk/~anc505/code/hasp/hasp.html...


Liskell is pretty much dead in the water. The site is still up but the code (in darcs repositories) is no longer accessible. Searching for another place to find the Liskell code lead me to this project.


Pro Tip : Examples first




Consider applying for YC's first-ever Fall batch! Applications are open till Aug 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: