
Support for writing GHC passes in Coq - lelf
http://www.megacz.com/berkeley/coq-in-ghc/
======
sgrove
I've been diving into Haskell more lately from the Clojure/Script world, and
it has a lot to admire. There's so much about it that's daunting though.

Is there an analogy for what this pulls off that the poor common-fp-programmer
can understand? Sounds like heterogeneous metaprogramming would let subsets of
Haskell (e.g. more restrictive languages) also join in metaprogramming, but
I'm not clear on why or how.

Definitely looking forward to learning more from the Haskell community and
their amazing projects!

~~~
chriswarbo
I suppose the really interesting part isn't the final result (the
metaprogramming part), but the Coq model of System FC1 and the linking to
GHC's Core passes.

Coq is a functional programming language, similar to Haskell, but with a much
more powerful ("dependent") type system. These powerful types let us specify
all kinds of stuff about our code, eg. instead of "an integer" we might say "a
prime between MIN and MAX whose binary representation is a palindrome".
Roughly speaking, if you can compute something with a pure fold, you can use
it in your types.

Having the compiler check our code in such detail gives us a lot of confidence
that our pre/post conditions are satisfied, that tricky calculations have been
implemented correctly and that edge-cases are eliminated. This doesn't really
matter for CRUD Web apps, but it's exactly what we want for compiler
optimisations.

~~~
cousin_it
> _Roughly speaking, if you can compute something with a pure fold, you can
> use it in your types._

I don't really understand that statement but it makes me really curious. Can
you expand it a bit? (Background: I can read Haskell but I have only a vague
idea of dependent types.)

~~~
tel
It's generally dangerous to allow non-terminating computation into your types
since it means you can no longer trust the logic of your type system (Turing
completeness implies logical inconsistency).

One way to limit the completeness of a language is to replace fixed-point
recursion (as is embodied in the Y combinator and all recursive languages
which are complete) by induction/coinduction. These two concepts "divide
general recursion in half" such that you can get a lot of work done without
actually having completeness/inconsistency.

Haskell for instance has induction via folds and coinduction via unfolds, but
since we're allowed to "cross the streams" in folds and unfolds you end up
with general recursion and inconsistency.

Coq disallows stream crossing.

~~~
juliangamble
_Coq disallows stream crossing_

Epic. Coq is the Dr. Egon Spengler of programming languages.

