
Morte: an intermediate language for super-optimizing functional programs - mercurial
http://www.haskellforall.com/2014/09/morte-intermediate-language-for-super.html
======
rrradical
I love the work this guy does. He consistently and often develops really
interesting Haskell libraries. Does anyone know his background?

~~~
Gabriel439
I was a PhD student in biochemistry, but most of my PhD work was structural
bioinformatics because I worked in a protein design research lab. Working on
my PhD project is how I got exposed to (and addicted to) Haskell and
programming in general, so I decided to change career paths to software
engineering so I could feed my programming habit and now I work at Twitter.

~~~
cstrahan
What sort of work are you doing at Twitter? Does Twitter use Haskell?

~~~
Gabriel439
I work on an internal analytics framework at Twitter.

Twitter doesn't use Haskell. The most Haskell I've done there is to write an
internal tool in Haskell (A shell-based interface to HDFS). Everybody here
knows that it's my mission to introduce Haskell more at Twitter and I have two
long plays to do so (Morte is part of one of them).

You would think that it would be easier to introduce Haskell at a Scala-based
company because of the strong similarities between the functional half of
Scala and Haskell, but it's actually quite the opposite: the marginal benefit
of switching to Haskell is smaller so it's harder to make the case to adopt
Haskell. This is why you see Haskell take hold more easily in companies
programming primarily in languages far-removed from Haskell (like PHP or
Python) because then the marginal benefit of switching is much higher.

~~~
tel
That reminds me of Joe Armstrong's talk—the best place to introduce new
technology is in a company which is already experiencing technology failure.
At that point, the pain is clear and options to resolve it command power and
premium.

~~~
vorg
Could be why so many Groovy shops switch to Scala.

------
JadeNB
I'm confused by this. It seems to be promising a normal form for all
expressions in a Turing-complete language—but that's equivalent to
guaranteeing termination, isn't it? Moreover, it promises to produce equal
results for equivalent programs, which would allow a solution of the halting
problem, wouldn't it?

I suspect that I've got some bad conceptual misunderstanding here; but, on the
other hand, I also have a hard time believing that, if beta- and eta-reduction
alone were sufficient to express such powerful optimisations, it would have
taken this long to discover that.

~~~
wyager
>Moreover, it promises to produce equal results for equivalent programs, which
would allow a solution of the halting problem, wouldn't it?

I believe this is the case. So the article's promise (as I read it) can not
hold true in the general case.

On a similar note, just write a program that runs the collatz conjecture and
prints the result and a program that prints 1. Run them through Morte. If they
compile to the same code, then boom, you've solved the Collatz conjecture :)

~~~
tel
You can't encode the Collatz Conjecture (in that way) in Morte. It would
require an infinite amount of computation and infinite loops have been
disallowed. You would have to get a little bit more creative with the
dependently typed parts of CIC and then finding a program which matches the
needed type is as of today an unsolved task.

------
gamegoblin
I have always wondered why I couldn't do something in Haskell like:

    
    
        {#- COMPILECOMPUTE #-}
        factorial 0 = 1
        factorial n = n * factorial (n - 1)
    

And have the compiler transform something like "factorial 5" into "120" at
compile time, since factorial is a pure function, it seems like that would be
doable? Of course you'd have to use your pragmas very judiciously to avoid
crazy compile times.

But there are some instances where, for code readability, I'd want to say "f
123" rather than whatever "f" evaluates to at 123, since "f 123" shows where
the value comes from, but at compile time I'd like that to be optimized out.

~~~
JadeNB
You _can_ do this, at the cost of some heavy lifting to express it:
[http://www.haskell.org/haskellwiki/Type_arithmetic](http://www.haskell.org/haskellwiki/Type_arithmetic).

P.S. This type of inlining was also discussed at
[http://stackoverflow.com/questions/19259114/why-are-
constant...](http://stackoverflow.com/questions/19259114/why-are-constant-
expressions-not-evaluated-at-compile-time-in-haskell).

------
mercurial
> Also, if you're wondering, the name Morte is a tribute to a talking skull
> from the game Planescape: Torment, since the Morte library is a "bare-bones"
> calculus of constructions.

Clearly a mark of good taste.

~~~
TelmoMenezes
Morte means "death" in Latin and also in my native language (Portuguese).

~~~
glibgil
Almost every native English speaker knows the meaning of morte. We have a
words like mortician which is a person who cares for the dead, mortgage which
is a plan to kill you debt, rigor mortis which is the stiffness of death and
mortal which means subject to death. Yes, we almost all know what morte means.
That is why it was the name given to a talking skull in a game. Just like love
and hate, however, we often use native words in English for our most basic
concepts. Death is one of those.

~~~
mercurial
You also have Mallory's "Le Morte d'Arthur" (no talking skull involved in this
one). That said, it was just a small nod to Gabriel's appreciation of the
game, which after so many years I still consider the best RPG ever made.

~~~
Gabriel439
I agree. Planescape: Torment was the best RPG ever. I still get chills
thinking about it.

