Skip to content

Commit 9b8f68c

Browse files
committed
New blog post
1 parent 3657212 commit 9b8f68c

File tree

1 file changed

+87
-0
lines changed

1 file changed

+87
-0
lines changed

blog/_posts/2016-11-17-splash.md

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
---
2+
layout: blog
3+
post-type: blog
4+
by: Martin Odersky
5+
title: SPLASH Amsterdam and Higher-kinded Types
6+
---
7+
8+
Two weaks ago I was in Amsterdam, where we had the Scala Symposium as
9+
part of the SPLASH conference. I gave a talk at the symposium and then
10+
later on a keynote at the main conference. I had a great time, staying
11+
in a hotel on one of Amsterdam's lovely canals and commuting by bike
12+
to the conference center. Amsterdam is a fantastic city for
13+
biking. Each day I picked another route along a different canal, and
14+
the route generally could not be long enough for me (I missed a couple
15+
of talks because of that). I noted that it's important to always stick
16+
to the traffic rules, for instance to give way to traffic coming from
17+
the right, or you would get into an accident between two bicycles;
18+
there are so many of them around.
19+
20+
SPLASH is a set of conferences running together (OOPSLA being one of
21+
the main ones), so you get exposed to a variety of topics and get to
22+
talk to people from many different areas. One talk that stood out for
23+
me was Simon Peyton Jones speaking about how they reform the UK
24+
curriculum to teach computational thinking to kids from primary school
25+
on. It's been Simon's main "other" occupation besides Haskell and he
26+
gave a fascinating talk that conveyed his great enthusiasm for the
27+
cause of teaching computing the right way to every kid. His message
28+
was that we have to act now, when things are waiting to be defined. A
29+
quote: "We know we have failed if, 10 years from now, the outcome is
30+
just that every kid can code Java".
31+
32+
At the Scala Symposium I was talking about how we implemented
33+
higher-kinded types in Dotty. This was a long and often painful
34+
journey. We tried overall four different approaches. Each of them was
35+
an effort of many weeks -- sometimes several months -- to implement
36+
the new scheme, debug it, and then finally discard it because we found
37+
out it was too hard to get right, or did not live up otherwise to
38+
expectations.
39+
40+
The original reason for trying so many different avenues had to do
41+
with DOT, which is intended to be the foundation of future Scala. DOT
42+
as it is has no povision for higher-kinded types, but it turns out
43+
that a restricted version of higher-kinded types can be
44+
straightforwardly encoded in it. That issue is not just academic
45+
because the _dotty_ compiler uses DOT's constructs as its core data
46+
structures. So what is hard to do in DOT tends to hard to implement in
47+
the compiler as well.
48+
49+
Originally, we played with the idea to restrict higher-kinded types to
50+
to just the kind of partial applications that can be conveniently
51+
encoded in DOT or _dotty_. The main problem was that this would have
52+
forced us to restrict the Scala language. More advanced idioms, such
53+
as type classes for `Monad` and `Functor` would have required rewrites
54+
and would not be as convenient to use. The boundary between what was
55+
expressible and what was illegal was also not very intuitive. For instance,
56+
one could define an abstract polymorphic subtype of `Maps` in the usual way:
57+
58+
59+
type M[K, V] <: Map[K, V]
60+
61+
But one would could not define a type where the parameters were reversed. I.e.
62+
63+
type M[V, K] <: Map[K, V]
64+
65+
would have been illegal.
66+
67+
To address these limitations, we played then with two more complicated
68+
encodings of higher-kinded types in _dotty_'s core types. Neither of
69+
these worked out very well so in the end we settled for the "brute
70+
force" approach of adding higher-kinded types without trying to re-use
71+
most of the core. All these attempts are described in the paper
72+
[Implementing Higher-Kinded Types in
73+
Dotty](https://infoscience.epfl.ch/record/222780/files/p51-odersky.pdf).
74+
The talk was not recorded but I have uploaded the
75+
[slides](http://www.slideshare.net/Odersky/implementing-higherkinded-types-in-dotty).
76+
77+
Another interesting development was that after the talk I got together
78+
with Sandro Stucki and Guillaume Martres and we hashed out a slight
79+
extension of DOT, which would make it much more convenient for more
80+
advanced dependent type programming and, as a side effect, would make
81+
it quite suitable to express higher-kinded types as well. If this
82+
works out it would be a case where compiler hacking influenced the way
83+
we do theory. It's usually more efficient to do theory first and
84+
implement it systematically once it's done, but sometimes going from
85+
practice to theory is the only route available.
86+
87+

0 commit comments

Comments
 (0)