<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>∃xistential Type &#187; types</title>
	<atom:link href="http://existentialtype.net/category/types/feed/" rel="self" type="application/rss+xml" />
	<link>http://existentialtype.net</link>
	<description>For People Who Like Type and Types</description>
	<lastBuildDate>Fri, 29 Oct 2010 15:00:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Fun with words</title>
		<link>http://existentialtype.net/2010/10/29/fun-with-words/</link>
		<comments>http://existentialtype.net/2010/10/29/fun-with-words/#comments</comments>
		<pubDate>Fri, 29 Oct 2010 15:00:12 +0000</pubDate>
		<dc:creator>washburn</dc:creator>
				<category><![CDATA[humour]]></category>
		<category><![CDATA[types]]></category>

		<guid isPermaLink="false">http://existentialtype.net/?p=386</guid>
		<description><![CDATA[I've always wanted to write a monkey inference system.]]></description>
			<content:encoded><![CDATA[<p>I've always wanted to write a <a href="http://thesaurus.com/browse/constraint">monkey</a> inference system.</p>
]]></content:encoded>
			<wfw:commentRss>http://existentialtype.net/2010/10/29/fun-with-words/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Resumption</title>
		<link>http://existentialtype.net/2009/04/04/resumption/</link>
		<comments>http://existentialtype.net/2009/04/04/resumption/#comments</comments>
		<pubDate>Sat, 04 Apr 2009 16:15:21 +0000</pubDate>
		<dc:creator>washburn</dc:creator>
				<category><![CDATA[languages]]></category>
		<category><![CDATA[research]]></category>
		<category><![CDATA[theory]]></category>
		<category><![CDATA[types]]></category>
		<category><![CDATA[dot]]></category>
		<category><![CDATA[scala]]></category>
		<category><![CDATA[scala classic]]></category>

		<guid isPermaLink="false">http://existentialtype.net/?p=277</guid>
		<description><![CDATA[That was a longer hiatus than I had intended. Partly because not everything went according to plan. My original plan was that, upon returning from my vacation, I would spend my remaining time at EPFL writing a technical report explaining everything I knew about the problems with Scala Classic. Instead, on my first day back [...]]]></description>
			<content:encoded><![CDATA[<p>That was a longer hiatus than I had intended.  Partly because not everything went according to plan.</p>
<p>My original plan was that, upon returning from my vacation, I would spend my remaining time at <a href="http://lamp.epfl.ch/">EPFL</a> writing a technical report explaining everything I knew about the problems with Scala Classic.  Instead, on my first day back in the office, Martin came by with a draft of a new formal system, DOT (for Dependent Object Types), that he came up with while he was on vacation.  After about four weeks I managed to root out pretty much all of the obvious problems with DOT, but another four weeks was not enough to get the proofs and the metatheory into a state that we were happy with.  I am not really sure what will happen with DOT in the long term.</p>
<p>There are a few clever things about DOT that avoid some of the problems I encountered with Scala Classic.  For example, Scala Classic only had intersection types while DOT has both intersection and union types, which solves some problems with computing the members of types.  However, with Scala Classic I was trying to model a minimal subset <a href="http://www.scala-lang.org/">Scala</a> language as it exists, without adding any new features that many never be supported by the full language.  I have no idea if we will see union types in the actual Scala implementation anytime soon.</p>
<p>The other thing DOT does is give up the goal of trying to be a minimal subset of Scala and throws out quite a few important things from a user perspective.  For example, there are no methods (only λ-abstractions), no existentials, no built-in inheritance or mix-in composition (though you can encode it by hand), and object fields must be syntactically values.</p>
<p>This last restriction is particularly important because it solves by fiat the problems that arose in Scala Classic from using paths that have an empty type in dependent type projections.  However, it also means that you may not be able to directly encode some Scala programs into DOT without an effect or termination analysis.  Therefore, while DOT has the potential to be a useful intermediary step, there will still be more work to be done to provide a semantics for a more realistic subset of the Scala language.</p>
<p>I have been in Copenhagen for a little over a month now, but I am not really ready to comment on the research I have been doing here yet.  So in the meantime I'll probably focus more on fonts and typography.</p>
]]></content:encoded>
			<wfw:commentRss>http://existentialtype.net/2009/04/04/resumption/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Literally dependent types</title>
		<link>http://existentialtype.net/2008/07/21/literally-dependent-types/</link>
		<comments>http://existentialtype.net/2008/07/21/literally-dependent-types/#comments</comments>
		<pubDate>Mon, 21 Jul 2008 17:26:29 +0000</pubDate>
		<dc:creator>washburn</dc:creator>
				<category><![CDATA[hacking]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[types]]></category>
		<category><![CDATA[dependent types]]></category>
		<category><![CDATA[implicit conversions]]></category>
		<category><![CDATA[literals]]></category>
		<category><![CDATA[scala]]></category>

		<guid isPermaLink="false">http://existentialtype.net/?p=264</guid>
		<description><![CDATA[Given that the formalization of Scala Classic has ground to a halt, for reasons I may go into later, I spent part of today hacking on the Scala compiler itself to add support for singleton literals. Currently, Scala allows singleton types for stable identifiers. My modification allows literals to be used in singleton types. I [...]]]></description>
			<content:encoded><![CDATA[<p>Given that <a href="http://existentialtype.net/2008/07/13/even-better-than-the-real-thing/">the formalization of Scala Classic</a> has ground to a halt, for reasons I may go into later, I spent part of today hacking on the Scala compiler itself to add support for singleton literals. Currently, Scala allows singleton types for stable identifiers.  My modification allows literals to be used in singleton types.  I can't promise that it will be in the forthcoming Scala 2.7.2 release, but I would like it to be.</p>
<p>Overall it was far less work than I was expecting.  Scala already internally supports what it calls "constant types", there is just no way to write them in Scala source code presently.  Consequently, most of the effort was in extending the parser.</p>
<p>Given my modifications, it is now possible to write code like the following:</p>
<pre class="scala">&nbsp;
scala<span style="color: #a00000;">&gt;</span> <a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">val</span></a> x <span style="color: #a00000;">:</span> <span style="color: #6666ff;">&quot;foo&quot;</span>.<a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">type</span></a> <span style="color: #a00000;">=</span> <span style="color: #6666ff;">&quot;foo&quot;</span>
x<span style="color: #a00000;">:</span> <span style="color: #6666ff;">&quot;foo&quot;</span>.<a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">type</span></a> <span style="color: #a00000;">=</span> foo
&nbsp;</pre>
<p>What I was not expecting was that out-of-the-box things like the following would work:</p>
<pre class="scala">&nbsp;
scala<span style="color: #a00000;">&gt;</span> <a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">val</span></a> x <span style="color: #a00000;">:</span> <span style="color: #6666ff;">&quot;foobar&quot;</span>.<a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">type</span></a> <span style="color: #a00000;">=</span> <span style="color: #6666ff;">&quot;foo&quot;</span> + <span style="color: #6666ff;">&quot;bar&quot;</span>
x<span style="color: #a00000;">:</span> <span style="color: #6666ff;">&quot;foobar&quot;</span>.<a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">type</span></a> <span style="color: #a00000;">=</span> foobar
scala<span style="color: #a00000;">&gt;</span> <a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">val</span></a> y <span style="color: #a00000;">:</span> <span style="color: #f78811;">10</span>.<a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">type</span></a> <span style="color: #a00000;">=</span> <span style="color: #f78811;">2</span> <span style="color: #a00000;">*</span> <span style="color: #f78811;">5</span>
y<span style="color: #a00000;">:</span> <span style="color: #f78811;">10</span>.<a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">type</span></a> <span style="color: #a00000;">=</span> <span style="color: #f78811;">10</span>
scala<span style="color: #a00000;">&gt;</span> <a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">def</span></a> frob<span style="color: #e77801;">&#40;</span>arg <span style="color: #a00000;">:</span> <span style="color: #f78811;">10</span>.<a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">type</span></a><span style="color: #e77801;">&#41;</span> <span style="color: #a00000;">:</span> <span style="color: #f78811;">6</span>.<a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">type</span></a> <span style="color: #a00000;">=</span> arg - <span style="color: #f78811;">4</span>
frob<span style="color: #a00000;">:</span> <span style="color: #e77801;">&#40;</span><span style="color: #f78811;">10</span>.<a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">type</span></a><span style="color: #e77801;">&#41;</span><span style="color: #f78811;">6</span>.<a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">type</span></a>
&nbsp;</pre>
<p>Unfortunately the excitement soon passes when you realize all the things you can't do with singleton literals (yet).  Even if we turn on the experimental dependent method support, you can't write things like</p>
<pre class="scala">&nbsp;
<a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">def</span></a> add<span style="color: #e77801;">&#40;</span>arg <span style="color: #a00000;">:</span> <a href="http://www.scala-lang.org/docu/files/api/index.html"><span style="color: #5555cc;">Int</span></a><span style="color: #e77801;">&#41;</span> <span style="color: #a00000;">:</span> <span style="color: #e77801;">&#40;</span>arg + <span style="color: #f78811;">5</span><span style="color: #e77801;">&#41;</span>.<a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">type</span></a> <span style="color: #a00000;">=</span> arg + <span style="color: #f78811;">5</span>
&nbsp;</pre>
<p>because these are exactly what they are called, singleton literals, not full-blown dependent types.</p>
<p>One cute example, based on a use suggested by Sean McDirmid, would be that some people might do something like the following with implicits:</p>
<pre class="scala">&nbsp;
<a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">implicit</span></a> stringToColor<span style="color: #e77801;">&#40;</span>arg <span style="color: #a00000;">:</span> <a href="http://www.scala-lang.org/docu/files/api/index.html"><span style="color: #99cc99;">String</span></a><span style="color: #e77801;">&#41;</span> <span style="color: #a00000;">:</span> java.<span style="color: #006600;">awt</span>.<span style="color: #006600;">Color</span> <span style="color: #a00000;">=</span> java.<span style="color: #006600;">awt</span>.<span style="color: #006600;">Color</span>.<span style="color: #006600;">getColor</span><span style="color: #e77801;">&#40;</span>arg<span style="color: #e77801;">&#41;</span>
&nbsp;</pre>
<p>However, with singleton literals you can tighten it up by ensuring that for some strings it will never fail:</p>
<pre class="scala">&nbsp;
<a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">implicit</span></a> redToColor<span style="color: #e77801;">&#40;</span>arg <span style="color: #a00000;">:</span> <span style="color: #6666ff;">&quot;red&quot;</span>.<a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">type</span></a><span style="color: #e77801;">&#41;</span> <span style="color: #a00000;">:</span> java.<span style="color: #006600;">awt</span>.<span style="color: #006600;">Color</span> <span style="color: #a00000;">=</span> java.<span style="color: #006600;">awt</span>.<span style="color: #006600;">Color</span>.<span style="color: #006600;">RED</span>
<a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">implicit</span></a> blueToColor<span style="color: #e77801;">&#40;</span>arg <span style="color: #a00000;">:</span> <span style="color: #6666ff;">&quot;blue&quot;</span>.<a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">type</span></a><span style="color: #e77801;">&#41;</span> <span style="color: #a00000;">:</span> java.<span style="color: #006600;">awt</span>.<span style="color: #006600;">Color</span> <span style="color: #a00000;">=</span> java.<span style="color: #006600;">awt</span>.<span style="color: #006600;">Color</span>.<span style="color: #006600;">BLUE</span>
&nbsp;</pre>
<p>Happily, the type inferencer already chooses the most specific implicit conversions.</p>
<p>In any event, they will hopefully become more useful as the type system continues to grow.  I am also sure someone will probably come up with a clever use for them that hasn't occurred to me yet.  If so, let me know.</p>
]]></content:encoded>
			<wfw:commentRss>http://existentialtype.net/2008/07/21/literally-dependent-types/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Even better than the real thing</title>
		<link>http://existentialtype.net/2008/07/13/even-better-than-the-real-thing/</link>
		<comments>http://existentialtype.net/2008/07/13/even-better-than-the-real-thing/#comments</comments>
		<pubDate>Sun, 13 Jul 2008 15:23:45 +0000</pubDate>
		<dc:creator>washburn</dc:creator>
				<category><![CDATA[research]]></category>
		<category><![CDATA[theory]]></category>
		<category><![CDATA[types]]></category>
		<category><![CDATA[explicit contexts]]></category>
		<category><![CDATA[featherweight scala]]></category>
		<category><![CDATA[pldi]]></category>
		<category><![CDATA[POPL]]></category>
		<category><![CDATA[scala]]></category>
		<category><![CDATA[scala classic]]></category>
		<category><![CDATA[soundness]]></category>
		<category><![CDATA[substitution]]></category>
		<category><![CDATA[teaching]]></category>

		<guid isPermaLink="false">http://existentialtype.net/?p=256</guid>
		<description><![CDATA[Several weeks ago I decided that instead of calling the core calculus that I have been working on Featherweight Scala, which could be confusing given that there is already a different calculus with that name, that I would call it Scala Classic. I had hoped to submit a paper on Scala Classic to POPL 2009, [...]]]></description>
			<content:encoded><![CDATA[<div style="text-align:center;"><a href="http://existentialtype.net/wp-content/uploads/2008/07/scalaclassic.png"><img class="aligncenter size-full wp-image-257" title="scalaclassic" src="http://existentialtype.net/wp-content/uploads/2008/07/scalaclassic.png" alt="Scala Classic" width="488" height="427" /></a></div>
<p>Several weeks ago I decided that instead of calling the core calculus that I have been working on Featherweight Scala, which could be confusing given that there is already a <a href="http://lampwww.epfl.ch/~odersky/papers/mfcs06.pdf">different calculus with that name</a>, that I would call it Scala Classic.</p>
<p>I had hoped to submit a paper on Scala Classic to <a href="http://www.cs.ucsd.edu/popl/09/">POPL 2009</a>, but it has been taking too long to work out the metatheory. Partly because I am developing a mechanized proof of type soundness in <a href="http://twelf.plparty.org/">Twelf</a>, and on my first attempt at representing heaps I think tried to be too clever.  However, a more traditional treatment of heaps leads to the need to <a href="http://www.cs.cmu.edu/~crary/papers/2008/excon.pdf">explicitly represent typing contexts</a>, rather than the implicit treatment of contexts more commonly used in Twelf.</p>
<p>This afternoon I finally finished the proof of the theorem that is traditionally called "substitution".  However, the proof of type preservation will also require another theorem formalizing a substitution-like property for singleton types.  I am hoping that I can prove that theorem more quickly now that I've built up all the explicit context theory.  I have not thought much about whether there are any unusual theorems needed to prove progress.</p>
<p>In any event, I would ideally have the proofs finished by the beginning of August.  My current plan is to try submitting the paper to <a href="http://www-plan.cs.colorado.edu/~pldi09/">PLDI</a> (which is even in Europe this year), unless some obviously better venue comes to my attention.</p>
<p>One of the reasons I would really like to have the proofs done by August is that I will be teaching a PhD level course here at <a href="http://www.epfl.ch/">EPFL</a> this fall on mechanized sepcifications and proofs, with a strong emphasis on deductive systems. It also looks like I may fill in some for a masters level course based on <a href="http://www.cis.upenn.edu/~bcpierce/tapl/">TAPL</a>.  So between those two things, I am not going to have nearly as much time for research as would be ideal.</p>
]]></content:encoded>
			<wfw:commentRss>http://existentialtype.net/2008/07/13/even-better-than-the-real-thing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Functors in Scala</title>
		<link>http://existentialtype.net/2008/05/26/functors-in-scala/</link>
		<comments>http://existentialtype.net/2008/05/26/functors-in-scala/#comments</comments>
		<pubDate>Mon, 26 May 2008 19:42:19 +0000</pubDate>
		<dc:creator>washburn</dc:creator>
				<category><![CDATA[hacking]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[types]]></category>
		<category><![CDATA[functors]]></category>
		<category><![CDATA[modules]]></category>
		<category><![CDATA[scala]]></category>
		<category><![CDATA[sml]]></category>

		<guid isPermaLink="false">http://existentialtype.net/?p=246</guid>
		<description><![CDATA[Following on my earlier entry on modules in Scala, I'll give an encoding of Standard ML style functors here. You can get a pretty close approximation by using class constructor arguments. However, I am going to cheat a little to get the closest encoding I think is possible by using the experimental support for dependent [...]]]></description>
			<content:encoded><![CDATA[<p>Following on my earlier entry on <a href="http://existentialtype.net/2008/05/26/modules-in-scala/">modules in Scala</a>, I'll give an encoding of Standard ML style functors here.  You can get a pretty close approximation by using <code>class</code> constructor arguments.  However, I am going to cheat a little to get the closest encoding I think is possible by using the experimental support for dependent method types.  You can get this by running <code>scala</code> or <code>scalac</code> with the option <code>-Xexperimental</code>.  It works okay at least some of the time, but no one has the time at the moment to commit to getting it in shape for general consumption.</p>
<p>So here is my example of how the encoding works.  First, the SML version:</p>
<pre>&nbsp;
signature Eq = sig
  type t
  val eq: t -&gt; t -&gt; bool
end
&nbsp;
signature RicherEq = sig
  include Eq
  val neq: t -&gt; t -&gt; bool
end
&nbsp;
functor mkRicherEq(arg : Eq) :&gt; RicherEq where type t = arg.t = struct
  type t = arg.t
  val eq = arg.eq
  fun neq x y = not (eq x y)
end
&nbsp;</pre>
<p>We can transliterate this example into Scala as:</p>
<pre class="scala">&nbsp;
<a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">type</span></a> Eq <span style="color: #a00000;">=</span> <span style="color: #e77801;">&#123;</span>
  <a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">type</span></a> T
  <a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">def</span></a> eq<span style="color: #e77801;">&#40;</span>x<span style="color: #a00000;">:</span> T<span style="color: #a00000;">,</span> y<span style="color: #a00000;">:</span> T<span style="color: #e77801;">&#41;</span><span style="color: #a00000;">:</span> <a href="http://www.scala-lang.org/docu/files/api/index.html"><span style="color: #5555cc;">Boolean</span></a>
<span style="color: #e77801;">&#125;</span>
&nbsp;
<a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">type</span></a> RicherEq <span style="color: #a00000;">=</span> <span style="color: #e77801;">&#123;</span>
  <a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">type</span></a> T
  <a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">def</span></a> eq<span style="color: #e77801;">&#40;</span>x<span style="color: #a00000;">:</span> T<span style="color: #a00000;">,</span> y<span style="color: #a00000;">:</span> T<span style="color: #e77801;">&#41;</span><span style="color: #a00000;">:</span> <a href="http://www.scala-lang.org/docu/files/api/index.html"><span style="color: #5555cc;">Boolean</span></a>
  <a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">def</span></a> neq<span style="color: #e77801;">&#40;</span>x<span style="color: #a00000;">:</span> T<span style="color: #a00000;">,</span> y<span style="color: #a00000;">:</span> T<span style="color: #e77801;">&#41;</span><span style="color: #a00000;">:</span> <a href="http://www.scala-lang.org/docu/files/api/index.html"><span style="color: #5555cc;">Boolean</span></a>
<span style="color: #e77801;">&#125;</span>
&nbsp;
<a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">def</span></a> mkRicherEq<span style="color: #e77801;">&#40;</span>arg<span style="color: #a00000;">:</span> Eq<span style="color: #e77801;">&#41;</span> <span style="color: #a00000;">:</span> RicherEq <span style="color: #e77801;">&#123;</span> <a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">type</span></a> T <span style="color: #a00000;">=</span> arg.<span style="color: #006600;">T</span> <span style="color: #e77801;">&#125;</span> <span style="color: #a00000;">=</span> <a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">new</span></a> <span style="color: #e77801;">&#123;</span>
  <a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">type</span></a> T <span style="color: #a00000;">=</span> arg.<span style="color: #006600;">T</span>
  <a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">def</span></a> eq<span style="color: #e77801;">&#40;</span>x<span style="color: #a00000;">:</span> T<span style="color: #a00000;">,</span> y<span style="color: #a00000;">:</span> T<span style="color: #e77801;">&#41;</span> <span style="color: #a00000;">=</span> arg.<span style="color: #006600;">eq</span><span style="color: #e77801;">&#40;</span>x<span style="color: #a00000;">,</span> y<span style="color: #e77801;">&#41;</span>
  <a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">def</span></a> neq<span style="color: #e77801;">&#40;</span>x<span style="color: #a00000;">:</span> T<span style="color: #a00000;">,</span> y<span style="color: #a00000;">:</span>T<span style="color: #e77801;">&#41;</span> <span style="color: #a00000;">=</span> <span style="color: #a00000;">!</span>eq<span style="color: #e77801;">&#40;</span>x<span style="color: #a00000;">,</span> y<span style="color: #e77801;">&#41;</span>
<span style="color: #e77801;">&#125;</span>
&nbsp;</pre>
<p>The only problem I discovered is that it is not possible to define <code>RicherEq</code> in terms of <code>Eq</code> as we could in SML:</p>
<pre class="scala">&nbsp;
scala<span style="color: #a00000;">&gt;</span> <a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">type</span></a> RicherEq <span style="color: #a00000;">=</span> Eq <span style="color: #e77801;">&#123;</span> <a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">def</span></a> neq<span style="color: #e77801;">&#40;</span>x<span style="color: #a00000;">:</span> T<span style="color: #a00000;">,</span> y<span style="color: #a00000;">:</span> T<span style="color: #e77801;">&#41;</span><span style="color: #a00000;">:</span> <a href="http://www.scala-lang.org/docu/files/api/index.html"><span style="color: #5555cc;">Boolean</span></a> <span style="color: #e77801;">&#125;</span>
<span style="color: #a00000;">&lt;</span>console<span style="color: #a00000;">&gt;:</span><span style="color: #f78811;">5</span><span style="color: #a00000;">:</span> error<span style="color: #a00000;">:</span> Parameter <a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">type</span></a> in structural refinement may
not refer to <a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">abstract</span></a> <a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">type</span></a> defined outside that same refinement
       <a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">type</span></a> RicherEq <span style="color: #a00000;">=</span> Eq <span style="color: #e77801;">&#123;</span> <a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">def</span></a> neq<span style="color: #e77801;">&#40;</span>x<span style="color: #a00000;">:</span> T<span style="color: #a00000;">,</span> y<span style="color: #a00000;">:</span> T<span style="color: #e77801;">&#41;</span><span style="color: #a00000;">:</span> <a href="http://www.scala-lang.org/docu/files/api/index.html"><span style="color: #5555cc;">Boolean</span></a> <span style="color: #e77801;">&#125;</span>
                                       ^
<span style="color: #a00000;">&lt;</span>console<span style="color: #a00000;">&gt;:</span><span style="color: #f78811;">5</span><span style="color: #a00000;">:</span> error<span style="color: #a00000;">:</span> Parameter <a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">type</span></a> in structural refinement may
not refer to <a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">abstract</span></a> <a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">type</span></a> defined outside that same refinement
       <a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">type</span></a> RicherEq <span style="color: #a00000;">=</span> Eq <span style="color: #e77801;">&#123;</span> <a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">def</span></a> neq<span style="color: #e77801;">&#40;</span>x<span style="color: #a00000;">:</span> T<span style="color: #a00000;">,</span> y<span style="color: #a00000;">:</span> T<span style="color: #e77801;">&#41;</span><span style="color: #a00000;">:</span> <a href="http://www.scala-lang.org/docu/files/api/index.html"><span style="color: #5555cc;">Boolean</span></a> <span style="color: #e77801;">&#125;</span>
                                             ^
&nbsp;</pre>
<p>Why this restriction exists I don't know.  In fact, this sort of refinement should work in the current version of Featherweight Scala, so perhaps it can be lifted eventually.</p>
<p>I still need to think about higher-order functors, and probably spend a few minutes researching existing proposals.  I think this is probably something that cannot be easily supported in Scala if it will require allowing method invocations to appear in paths.  However, off hand that only seems like it should be necessary for applicative higher-order functors, but again I definitely need to think it through.</p>
]]></content:encoded>
			<wfw:commentRss>http://existentialtype.net/2008/05/26/functors-in-scala/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Modules in Scala</title>
		<link>http://existentialtype.net/2008/05/26/modules-in-scala/</link>
		<comments>http://existentialtype.net/2008/05/26/modules-in-scala/#comments</comments>
		<pubDate>Mon, 26 May 2008 15:48:18 +0000</pubDate>
		<dc:creator>washburn</dc:creator>
				<category><![CDATA[hacking]]></category>
		<category><![CDATA[languages]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[types]]></category>
		<category><![CDATA[modules]]></category>
		<category><![CDATA[scala]]></category>
		<category><![CDATA[sml]]></category>

		<guid isPermaLink="false">http://existentialtype.net/?p=245</guid>
		<description><![CDATA[I just saw a thread on Lambda the Ultimate where I think the expressive power of Scala in comparison to Standard ML's module system was misrepresented. I don't want to go into all of the issues at the moment, but I figured out would point out that you can get the same structural typing, opaque [...]]]></description>
			<content:encoded><![CDATA[<p>I just saw a <a href="http://lambda-the-ultimate.org/node/2808">thread on Lambda the Ultimate</a> where I think the expressive power of Scala in comparison to Standard ML's module system was misrepresented.  I don't want to go into all of the issues at the moment, but I figured out would point out that you can get the same structural typing, opaque sealing, and even the equivalent of SML's <code>where type</code> clause.  </p>
<p>For example, consider the following SML signature:</p>
<pre>&nbsp;
signature Nat = sig
  type t
  val z: t
  val s: t -&gt; t
end
&nbsp;</pre>
<p>This signature can be translated in to Scala as:</p>
<pre class="scala">&nbsp;
<a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">type</span></a> Nat <span style="color: #a00000;">=</span> <span style="color: #e77801;">&#123;</span>
  <a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">type</span></a> T
  <a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">val</span></a> z<span style="color: #a00000;">:</span> T
  <a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">def</span></a> s<span style="color: #e77801;">&#40;</span>arg<span style="color: #a00000;">:</span> T<span style="color: #e77801;">&#41;</span><span style="color: #a00000;">:</span> T
<span style="color: #e77801;">&#125;</span>
&nbsp;</pre>
<p>It is then possible to create an implementation of this type, and opaquely seal it (hiding the definition of <code>T</code>).  In SML:</p>
<pre>&nbsp;
structure nat :&gt; Nat = struct
  type t = int
  val z = 0
  fun s n = n + 1
end
&nbsp;</pre>
<p>In Scala:</p>
<pre class="scala">&nbsp;
<a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">val</span></a> nat <span style="color: #a00000;">:</span> Nat <span style="color: #a00000;">=</span> <a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">new</span></a> <span style="color: #e77801;">&#123;</span>
  <a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">type</span></a> T <span style="color: #a00000;">=</span> <a href="http://www.scala-lang.org/docu/files/api/index.html"><span style="color: #5555cc;">Int</span></a>
  <a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">val</span></a> z <span style="color: #a00000;">=</span> <span style="color: #f78811;">0</span>
  <a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">def</span></a> s<span style="color: #e77801;">&#40;</span>arg<span style="color: #a00000;">:</span> <a href="http://www.scala-lang.org/docu/files/api/index.html"><span style="color: #5555cc;">Int</span></a><span style="color: #e77801;">&#41;</span> <span style="color: #a00000;">=</span> arg + <span style="color: #f78811;">1</span>
<span style="color: #e77801;">&#125;</span>
&nbsp;</pre>
<p>In many cases when programming with SML modules it is necessary or convenient to give a module that reveals the definition of an abstract type.  In the above example, this can be done by adding a <code>where type</code> clause to the first line:</p>
<pre>&nbsp;
structure nat :&gt; Nat where type t = int = struct
...
&nbsp;</pre>
<p>We can do the same thing in Scala using refinements:</p>
<pre class="scala">&nbsp;
<a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">val</span></a> nat <span style="color: #a00000;">:</span> Nat <span style="color: #e77801;">&#123;</span> <a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">type</span></a> T <span style="color: #a00000;">=</span> <a href="http://www.scala-lang.org/docu/files/api/index.html"><span style="color: #5555cc;">Int</span></a> <span style="color: #e77801;">&#125;</span> <span style="color: #a00000;">=</span> <a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">new</span></a> <span style="color: #e77801;">&#123;</span>
...
&nbsp;</pre>
<p>Great, right?  Well, almost.  The problem is that structural types are still a bit buggy in Scala compiler at present.  So, while the above typechecks, you can't quite use it yet:</p>
<pre class="scala">&nbsp;
scala<span style="color: #a00000;">&gt;</span> nat.<span style="color: #006600;">s</span><span style="color: #e77801;">&#40;</span>nat.<span style="color: #006600;">z</span><span style="color: #e77801;">&#41;</span>
java.<span style="color: #006600;">lang</span>.<span style="color: #006600;">NoSuchMethodException</span><span style="color: #a00000;">:</span> $anon$<span style="color: #f78811;">1</span>.<span style="color: #006600;">s</span><span style="color: #e77801;">&#40;</span>java.<span style="color: #006600;">lang</span>.<a href="http://www.scala-lang.org/docu/files/api/index.html"><span style="color: #99cc99;">Object</span></a><span style="color: #e77801;">&#41;</span>
        at java.<span style="color: #006600;">lang</span>.<span style="color: #006600;">Class</span>.<span style="color: #006600;">getMethod</span><span style="color: #e77801;">&#40;</span>Class.<span style="color: #006600;">java</span><span style="color: #a00000;">:</span><span style="color: #f78811;">1581</span><span style="color: #e77801;">&#41;</span>
        at .<span style="color: #006600;">reflMethod</span>$Method1<span style="color: #e77801;">&#40;</span><span style="color: #a00000;">&lt;</span>console<span style="color: #a00000;">&gt;:</span><span style="color: #f78811;">7</span><span style="color: #e77801;">&#41;</span>
        at .<span style="color: #a00000;">&lt;</span>init<span style="color: #a00000;">&gt;</span><span style="color: #e77801;">&#40;</span><span style="color: #a00000;">&lt;</span>console<span style="color: #a00000;">&gt;:</span><span style="color: #f78811;">7</span><span style="color: #e77801;">&#41;</span>
        at .<span style="color: #a00000;">&lt;</span>clinit<span style="color: #a00000;">&gt;</span><span style="color: #e77801;">&#40;</span><span style="color: #a00000;">&lt;</span>console<span style="color: #a00000;">&gt;</span><span style="color: #e77801;">&#41;</span>
        at RequestResult$.<span style="color: #a00000;">&lt;</span>init<span style="color: #a00000;">&gt;</span><span style="color: #e77801;">&#40;</span><span style="color: #a00000;">&lt;</span>console<span style="color: #a00000;">&gt;:</span><span style="color: #f78811;">3</span><span style="color: #e77801;">&#41;</span>
        at RequestResult$.<span style="color: #a00000;">&lt;</span>clinit<span style="color: #a00000;">&gt;</span><span style="color: #e77801;">&#40;</span><span style="color: #a00000;">&lt;</span>console<span style="color: #a00000;">&gt;</span><span style="color: #e77801;">&#41;</span>
        at RequestResult$result<span style="color: #e77801;">&#40;</span><span style="color: #a00000;">&lt;</span>console<span style="color: #a00000;">&gt;</span><span style="color: #e77801;">&#41;</span>
        at sun.<span style="color: #006600;">reflect</span>.<span style="color: #006600;">NativeMethodAccessorImpl</span>.<span style="color: #006600;">invoke0</span><span style="color: #e77801;">&#40;</span>Native Method<span style="color: #e77801;">&#41;</span>
        at sun.<span style="color: #006600;">reflec</span>...
&nbsp;</pre>
<p>There were some issues raised about how faithful an encoding of SML functors, and well-known extensions for higher-order functors, one can get in Scala.  Indeed, off the top of my head it is not entirely clear.  So I need to think more about that before I write some examples.  </p>
]]></content:encoded>
			<wfw:commentRss>http://existentialtype.net/2008/05/26/modules-in-scala/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Featherweight Scala lives</title>
		<link>http://existentialtype.net/2008/05/26/featherweight-scala-lives/</link>
		<comments>http://existentialtype.net/2008/05/26/featherweight-scala-lives/#comments</comments>
		<pubDate>Mon, 26 May 2008 10:54:10 +0000</pubDate>
		<dc:creator>washburn</dc:creator>
				<category><![CDATA[research]]></category>
		<category><![CDATA[theory]]></category>
		<category><![CDATA[types]]></category>
		<category><![CDATA[f-bounded quantification]]></category>
		<category><![CDATA[featherweight scala]]></category>
		<category><![CDATA[scala]]></category>
		<category><![CDATA[type checking]]></category>
		<category><![CDATA[undecidability]]></category>

		<guid isPermaLink="false">http://existentialtype.net/?p=244</guid>
		<description><![CDATA[With everything else I've been having to deal with the past couple months, I have not made nearly as much progress on Featherweight Scala as I would have liked. Fortunately, in the past two weeks I have finally started to get back on track. Probably what makes working out the design of Featherweight Scala so [...]]]></description>
			<content:encoded><![CDATA[<p>With everything else I've been having to deal with the past couple months, I have not made nearly as much progress on Featherweight Scala as I would have liked.  Fortunately, in the past two weeks I have finally started to get back on track.</p>
<p>Probably what makes working out the design of Featherweight Scala so difficult is that I am trying my best to commit to it being a valid subset of Scala.  It seems like whenever I try to simplify one part of the language, it just introduces a complication elsewhere.   Still, I think so far that I have been able to ensure that it is a subset with two exceptions.</p>
<p>The first exception is that some programs in Featherweight Scala will diverge in cases where the Scala compiler will generate a terminating program.  This is because in programs that attempt to access an uninitialized field, Scala will return <code>null</code>, while Featherweight Scala diverges.  Since the program many never attempt to use the  <code>null</code> value, it may simple terminate without raising a <code>NullPointerException</code>.</p>
<p>The second exception arises because type checking in Featherweight Scala's type system is most likely undecidable.  Given that the design is in flux, I haven't precisely verified this, but it seems quite plausible given its expressive power is similar to languages where type checking is known to be undecidable.  Because type checking is undecidable, and the Scala language implementation attempts to have its type checking phase be terminating, there should be some programs that can be shown to be well-typed in Featherweight Scala that the Scala compiler will reject.</p>
<p>I think the other thing I've determined is that I do not understand F-bounded quantification as well as I thought I did.  At least, I find myself worried about the cases where the typing rules presently require  templates, that have not yet been verified to be well-formed, to be introduced as hypotheses while verifying their own correctness.  So I need to do some additional reading to see how some other languages deal with this issue.  Certainly I can put my mind at ease by making the type system more restrictive, but I do not want to be so restrictive that it is no longer reasonable to call the language Featherweight Scala.</p>
<p><strong>Update</strong>: Okay, so after looking at Featherweight Generic Java and &nu;Obj again more closely, they both do essentially the same kind of thing.  In FGJ, the class table is well-formed if all its classes are well-formed, but checking a class's well-formedness may require presupposing that that class tale is well-formed. In &nu;Obj, the well-formedness of recursive record types  is checked under the assumption that the record's self-name has the type of the record.  Certainly the same sort of things come up when verifying the well-formedness of recursive functions and recursive types, but at least there what is being assumed is at a higher level of abstraction: when checking a recursive function you assume that the function has some well-formed type, or when checking a recursive type you assume that the type has some well-formed kind.</p>
]]></content:encoded>
			<wfw:commentRss>http://existentialtype.net/2008/05/26/featherweight-scala-lives/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Revisiting higher-rank impredicative polymorphism in Scala</title>
		<link>http://existentialtype.net/2008/05/26/revisiting-higher-rank-impredicative-polymorphism-in-scala/</link>
		<comments>http://existentialtype.net/2008/05/26/revisiting-higher-rank-impredicative-polymorphism-in-scala/#comments</comments>
		<pubDate>Mon, 26 May 2008 10:23:36 +0000</pubDate>
		<dc:creator>washburn</dc:creator>
				<category><![CDATA[hacking]]></category>
		<category><![CDATA[languages]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[types]]></category>
		<category><![CDATA[bounded polymorphism]]></category>
		<category><![CDATA[higher-rank]]></category>
		<category><![CDATA[impredicativity]]></category>
		<category><![CDATA[scala]]></category>
		<category><![CDATA[type functions]]></category>
		<category><![CDATA[universal quantification]]></category>

		<guid isPermaLink="false">http://existentialtype.net/?p=243</guid>
		<description><![CDATA[I've been meaning to write this up for a while, but it seems like there has always been something else I really ought to be doing. So I expect this will be a bit more terse than I might like. Anyway, when I wrote about encoding higher-rank universal quantification in Scala back in March, I [...]]]></description>
			<content:encoded><![CDATA[<p>I've been meaning to write this up for a while, but it seems like there has always been something else I really ought to be doing.  So I expect this will be a bit more terse than I might like.  Anyway, when I wrote about <a href="http://existentialtype.net/2008/03/09/higher-rank-impredicative-polymorphism-in-scala/">encoding higher-rank universal quantification in Scala back in March</a>, I used a rather elaborate scheme involving the use of Scala's first-class existential quantifiers.  While this was the point of the exercise, surprisingly, no one called me on the fact that if you just want higher-rank impredicative polymorphism in Scala, there is a much simpler encoding.  Maybe it was obvious to everyone or no one read closely enough to think of raising the issue.  So today, I'll explain the better way to encode them.</p>
<p>First we can define an infinite family of traits to represent <i>n</i>-ary universal quantification, much like Scala represents <i>n</i>-ary functions types:</p>
<pre class="scala">&nbsp;
<a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">trait</span></a> Univ1<span style="color: #e77801;">&#91;</span>Bound1<span style="color: #a00000;">,</span>Body<span style="color: #e77801;">&#91;</span><span style="color: #a00000;">_</span><span style="color: #e77801;">&#93;</span><span style="color: #e77801;">&#93;</span> <span style="color: #e77801;">&#123;</span>
   <a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">def</span></a> Apply<span style="color: #e77801;">&#91;</span>T1<span style="color: #a00000;">&lt;:</span>Bound1<span style="color: #e77801;">&#93;</span> <span style="color: #a00000;">:</span> Body<span style="color: #e77801;">&#91;</span>T1<span style="color: #e77801;">&#93;</span>
<span style="color: #e77801;">&#125;</span>
&nbsp;
<a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">trait</span></a> Univ2<span style="color: #e77801;">&#91;</span>Bound1<span style="color: #a00000;">,</span>Bound2<span style="color: #a00000;">,</span>Body<span style="color: #e77801;">&#91;</span><span style="color: #a00000;">_,_</span><span style="color: #e77801;">&#93;</span><span style="color: #e77801;">&#93;</span> <span style="color: #e77801;">&#123;</span>
   <a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">def</span></a> Apply<span style="color: #e77801;">&#91;</span>T1<span style="color: #a00000;">&lt;:</span>Bound1<span style="color: #a00000;">,</span>T2<span style="color: #a00000;">&lt;:</span>Bound2<span style="color: #e77801;">&#93;</span> <span style="color: #a00000;">:</span> Body<span style="color: #e77801;">&#91;</span>T1<span style="color: #a00000;">,</span>T2<span style="color: #e77801;">&#93;</span>
<span style="color: #e77801;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">// ... so on for N &gt; 2</span>
&nbsp;</pre>
<p>Really, the key to this encoding is the use of higher-kinded quantification to encode the binding structure of the quantifier.  </p>
<p>Now it is possible to write some examples similar to what I gave previously, but more concisely:</p>
<pre class="scala">&nbsp;
<a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">object</span></a> Test <a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">extends</span></a> Application <span style="color: #e77801;">&#123;</span>
   <a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">def</span></a> id<span style="color: #e77801;">&#91;</span>T<span style="color: #e77801;">&#93;</span><span style="color: #e77801;">&#40;</span>x <span style="color: #a00000;">:</span> T<span style="color: #e77801;">&#41;</span> <span style="color: #a00000;">=</span> x
&nbsp;
   <a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">type</span></a> Id<span style="color: #e77801;">&#91;</span>T<span style="color: #e77801;">&#93;</span> <span style="color: #a00000;">=</span> T <span style="color: #a00000;">=&gt;</span> T
   <a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">val</span></a> id <span style="color: #a00000;">=</span> <a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">new</span></a> Univ1<span style="color: #e77801;">&#91;</span><a href="http://www.scala-lang.org/docu/files/api/index.html"><span style="color: #5555cc;">Any</span></a><span style="color: #a00000;">,</span>Id<span style="color: #e77801;">&#93;</span>
     <span style="color: #e77801;">&#123;</span> <a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">def</span></a> Apply<span style="color: #e77801;">&#91;</span>T <span style="color: #a00000;">&lt;:</span> <a href="http://www.scala-lang.org/docu/files/api/index.html"><span style="color: #5555cc;">Any</span></a><span style="color: #e77801;">&#93;</span> <span style="color: #a00000;">:</span> Id<span style="color: #e77801;">&#91;</span>T<span style="color: #e77801;">&#93;</span> <span style="color: #a00000;">=</span> id<span style="color: #e77801;">&#91;</span>T<span style="color: #e77801;">&#93;</span> <span style="color: #a00000;">_</span> <span style="color: #e77801;">&#125;</span>
&nbsp;
   <a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">val</span></a> idString <span style="color: #a00000;">=</span> id.<span style="color: #006600;">Apply</span><span style="color: #e77801;">&#91;</span><a href="http://www.scala-lang.org/docu/files/api/index.html"><span style="color: #99cc99;">String</span></a><span style="color: #e77801;">&#93;</span>
   <a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">val</span></a> idStringList <span style="color: #a00000;">=</span> id.<span style="color: #006600;">Apply</span><span style="color: #e77801;">&#91;</span><a href="http://www.scala-lang.org/docu/files/api/index.html"><span style="color: #99cc99;">List</span></a><span style="color: #e77801;">&#91;</span><a href="http://www.scala-lang.org/docu/files/api/index.html"><span style="color: #99cc99;">String</span></a><span style="color: #e77801;">&#93;</span><span style="color: #e77801;">&#93;</span>
&nbsp;
   println<span style="color: #e77801;">&#40;</span>idString<span style="color: #e77801;">&#40;</span><span style="color: #6666ff;">&quot;Foo&quot;</span><span style="color: #e77801;">&#41;</span><span style="color: #e77801;">&#41;</span>
   println<span style="color: #e77801;">&#40;</span>idStringList<span style="color: #e77801;">&#40;</span><a href="http://www.scala-lang.org/docu/files/api/index.html"><span style="color: #99cc99;">List</span></a><span style="color: #e77801;">&#40;</span><span style="color: #6666ff;">&quot;Foo&quot;</span><span style="color: #a00000;">,</span> <span style="color: #6666ff;">&quot;Bar&quot;</span><span style="color: #a00000;">,</span> <span style="color: #6666ff;">&quot;Baz&quot;</span><span style="color: #e77801;">&#41;</span><span style="color: #e77801;">&#41;</span><span style="color: #e77801;">&#41;</span>
&nbsp;
   <a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">type</span></a> <a href="http://www.scala-lang.org/docu/files/api/index.html"><span style="color: #5555cc;">Double</span></a><span style="color: #e77801;">&#91;</span>T<span style="color: #e77801;">&#93;</span> <span style="color: #a00000;">=</span> T <span style="color: #a00000;">=&gt;</span> <span style="color: #e77801;">&#40;</span>T<span style="color: #a00000;">,</span> T<span style="color: #e77801;">&#41;</span>
   <a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">val</span></a> double <span style="color: #a00000;">=</span> <a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">new</span></a> Univ1<span style="color: #e77801;">&#91;</span><a href="http://www.scala-lang.org/docu/files/api/index.html"><span style="color: #5555cc;">Any</span></a><span style="color: #a00000;">,</span><a href="http://www.scala-lang.org/docu/files/api/index.html"><span style="color: #5555cc;">Double</span></a><span style="color: #e77801;">&#93;</span>
     <span style="color: #e77801;">&#123;</span> <a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">def</span></a> Apply<span style="color: #e77801;">&#91;</span>T <span style="color: #a00000;">&lt;:</span> <a href="http://www.scala-lang.org/docu/files/api/index.html"><span style="color: #5555cc;">Any</span></a><span style="color: #e77801;">&#93;</span> <span style="color: #a00000;">:</span> <a href="http://www.scala-lang.org/docu/files/api/index.html"><span style="color: #5555cc;">Double</span></a><span style="color: #e77801;">&#91;</span>T<span style="color: #e77801;">&#93;</span> <span style="color: #a00000;">=</span> <span style="color: #e77801;">&#40;</span>x <span style="color: #a00000;">:</span> T<span style="color: #e77801;">&#41;</span> <span style="color: #a00000;">=&gt;</span> <span style="color: #e77801;">&#40;</span>x<span style="color: #a00000;">,</span> x<span style="color: #e77801;">&#41;</span> <span style="color: #e77801;">&#125;</span>
&nbsp;
   <a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">val</span></a> doubleString <span style="color: #a00000;">=</span> double.<span style="color: #006600;">Apply</span><span style="color: #e77801;">&#91;</span><a href="http://www.scala-lang.org/docu/files/api/index.html"><span style="color: #99cc99;">String</span></a><span style="color: #e77801;">&#93;</span>
   <a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">val</span></a> doubleStringList <span style="color: #a00000;">=</span> double.<span style="color: #006600;">Apply</span><span style="color: #e77801;">&#91;</span><a href="http://www.scala-lang.org/docu/files/api/index.html"><span style="color: #99cc99;">List</span></a><span style="color: #e77801;">&#91;</span><a href="http://www.scala-lang.org/docu/files/api/index.html"><span style="color: #99cc99;">String</span></a><span style="color: #e77801;">&#93;</span><span style="color: #e77801;">&#93;</span>
&nbsp;
   println<span style="color: #e77801;">&#40;</span>doubleString<span style="color: #e77801;">&#40;</span><span style="color: #6666ff;">&quot;Foo&quot;</span><span style="color: #e77801;">&#41;</span><span style="color: #e77801;">&#41;</span>
   println<span style="color: #e77801;">&#40;</span>doubleStringList<span style="color: #e77801;">&#40;</span><a href="http://www.scala-lang.org/docu/files/api/index.html"><span style="color: #99cc99;">List</span></a><span style="color: #e77801;">&#40;</span><span style="color: #6666ff;">&quot;Foo&quot;</span><span style="color: #a00000;">,</span> <span style="color: #6666ff;">&quot;Bar&quot;</span><span style="color: #a00000;">,</span> <span style="color: #6666ff;">&quot;Baz&quot;</span><span style="color: #e77801;">&#41;</span><span style="color: #e77801;">&#41;</span><span style="color: #e77801;">&#41;</span>
<span style="color: #e77801;">&#125;</span>
&nbsp;</pre>
<p>As I mentioned previously, this example would be much improved by support for anonymous type functions in Scala.  I am pretty sure Scala will eventually support them, as they would not require any deep changes in the implementation. They could be just implemented by desugaring to a higher-kinded type alias with a fresh name, but depending on when that desugaring is performed, it is possible that it would result in poor error messages.  Supporting curried type functions is also quite desirable, but given my current knowledge of the internals, that seems like adding them will require some more elaborate changes.</p>
<p>I think  <a href="http://lamp.epfl.ch/~cremet/">Vincent Cremet</a> was the first person to suggest this sort of encoding, and I vaguely recall reading about it on one of the Scala mailing lists, but I could not find the message after a little bit of time spent searching.</p>
]]></content:encoded>
			<wfw:commentRss>http://existentialtype.net/2008/05/26/revisiting-higher-rank-impredicative-polymorphism-in-scala/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>A new species</title>
		<link>http://existentialtype.net/2008/04/30/a-new-species/</link>
		<comments>http://existentialtype.net/2008/04/30/a-new-species/#comments</comments>
		<pubDate>Wed, 30 Apr 2008 06:55:50 +0000</pubDate>
		<dc:creator>washburn</dc:creator>
				<category><![CDATA[languages]]></category>
		<category><![CDATA[papers]]></category>
		<category><![CDATA[theory]]></category>
		<category><![CDATA[types]]></category>
		<category><![CDATA[girard]]></category>
		<category><![CDATA[graphs]]></category>
		<category><![CDATA[haskell]]></category>
		<category><![CDATA[intersection]]></category>
		<category><![CDATA[LtU]]></category>
		<category><![CDATA[ludics]]></category>
		<category><![CDATA[species]]></category>

		<guid isPermaLink="false">http://existentialtype.net/?p=239</guid>
		<description><![CDATA[I spent some time last night looking more closely at Carette and Uszkey's new paper on species, as mentioned recently on Lambda the Ultimate. I mostly concentrated on the first few sections and the Haskell bit at the end. They say many tantalizing things, and I had kind of hoped the punchline would be something [...]]]></description>
			<content:encoded><![CDATA[<p>I spent some time last night looking more closely at Carette and Uszkey's new paper on <a href="http://www.cas.mcmaster.ca/~carette/species/">species</a>, as mentioned recently on <a href="http://lambda-the-ultimate.org/node/2785">Lambda the Ultimate</a>.  I mostly concentrated on the first few sections and the Haskell bit at the end.  They say many tantalizing things, and I had kind of hoped the punchline would be something like "here is how you can write code in a beautifully functional style over graphs and cyclic structures" (assuming I understood the potential of species correctly).  Perhaps in a follow up paper.</p>
<p>I also found it interesting that their dot product operator sounds more like the traditional Cartesian product type (one of each type), and their Cartesian product type sounds much more like an intersection type (the value is a structure having both types).  Perhaps it is a notational holdover from previous work on species.  It also seem to make for some nice concrete examples of the "locative" aspects of Girard's <a href="http://en.wikipedia.org/wiki/Ludics">Ludics</a>.</p>
<p>Now back to reviewing journal and ICFP papers...</p>
]]></content:encoded>
			<wfw:commentRss>http://existentialtype.net/2008/04/30/a-new-species/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Correction on existential unpacking</title>
		<link>http://existentialtype.net/2008/03/09/correction-on-existential-unpacking/</link>
		<comments>http://existentialtype.net/2008/03/09/correction-on-existential-unpacking/#comments</comments>
		<pubDate>Sun, 09 Mar 2008 20:53:41 +0000</pubDate>
		<dc:creator>washburn</dc:creator>
				<category><![CDATA[hacking]]></category>
		<category><![CDATA[languages]]></category>
		<category><![CDATA[meta]]></category>
		<category><![CDATA[types]]></category>
		<category><![CDATA[bugs]]></category>
		<category><![CDATA[correction]]></category>
		<category><![CDATA[existentials]]></category>
		<category><![CDATA[pattern matching]]></category>
		<category><![CDATA[scala]]></category>

		<guid isPermaLink="false">http://existentialtype.net/2008/03/09/correction-on-existential-unpacking/</guid>
		<description><![CDATA[(WordPress ate my first draft, grrr.) So after thinking about it further, I was incorrect, and it is possible to explicitly unpack existentials in Scala. As with some other languages, it is done via pattern matching. The following example illustrates how: val x : List&#91;T&#93; forSome &#123; type T &#125; = List&#40;42&#41; val w = [...]]]></description>
			<content:encoded><![CDATA[<p>(WordPress ate my first draft, grrr.)</p>
<p>So after thinking about it further, <a href="http://existentialtype.net/2008/03/09/higher-rank-impredicative-polymorphism-in-scala/">I was incorrect</a>, and it is possible to explicitly unpack existentials in Scala.  As with some other languages, it is done via pattern matching.  The following example illustrates how:</p>
<blockquote>
<pre class="scala"><a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">val</span></a> x <span style="color: #a00000;">:</span> <a href="http://www.scala-lang.org/docu/files/api/index.html"><span style="color: #99cc99;">List</span></a><span style="color: #e77801;">&#91;</span>T<span style="color: #e77801;">&#93;</span> <a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">forSome</span></a> <span style="color: #e77801;">&#123;</span> <a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">type</span></a> T <span style="color: #e77801;">&#125;</span> <span style="color: #a00000;">=</span> <a href="http://www.scala-lang.org/docu/files/api/index.html"><span style="color: #99cc99;">List</span></a><span style="color: #e77801;">&#40;</span><span style="color: #f78811;">42</span><span style="color: #e77801;">&#41;</span>
<a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">val</span></a> w <span style="color: #a00000;">=</span> x <a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #000099;">match</span></a> <span style="color: #e77801;">&#123;</span> <a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #000099;">case</span></a> y <span style="color: #a00000;">:</span> <a href="http://www.scala-lang.org/docu/files/api/index.html"><span style="color: #99cc99;">List</span></a><span style="color: #e77801;">&#91;</span>u<span style="color: #e77801;">&#93;</span> <span style="color: #a00000;">=&gt;</span> <span style="color: #e77801;">&#40;</span><span style="color: #e77801;">&#40;</span>z <span style="color: #a00000;">:</span> u<span style="color: #e77801;">&#41;</span> <span style="color: #a00000;">=&gt;</span> z<span style="color: #e77801;">&#41;</span><span style="color: #e77801;">&#40;</span>y.<span style="color: #006600;">head</span><span style="color: #e77801;">&#41;</span> <span style="color: #e77801;">&#125;</span></pre>
</blockquote>
<p>However, in practice this functionality seems to be rather fragile.  For example, the following two variations are rejected:</p>
<blockquote>
<pre class="scala"><a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">val</span></a> x <span style="color: #a00000;">:</span> T <a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">forSome</span></a> <span style="color: #e77801;">&#123;</span> <a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">type</span></a> T <span style="color: #e77801;">&#125;</span> <span style="color: #a00000;">=</span> <span style="color: #f78811;">42</span>
<a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">val</span></a> w <span style="color: #a00000;">=</span> x <a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #000099;">match</span></a> <span style="color: #e77801;">&#123;</span> <a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #000099;">case</span></a> y <span style="color: #a00000;">:</span> u <span style="color: #a00000;">=&gt;</span> <span style="color: #e77801;">&#40;</span><span style="color: #e77801;">&#40;</span>z <span style="color: #a00000;">:</span> u<span style="color: #e77801;">&#41;</span> <span style="color: #a00000;">=&gt;</span> z<span style="color: #e77801;">&#41;</span><span style="color: #e77801;">&#40;</span>y<span style="color: #e77801;">&#41;</span> <span style="color: #e77801;">&#125;</span></pre>
</blockquote>
<p>and</p>
<blockquote>
<pre class="scala"><a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">val</span></a> x <span style="color: #a00000;">:</span> <a href="http://www.scala-lang.org/docu/files/api/index.html"><span style="color: #99cc99;">List</span></a><span style="color: #e77801;">&#91;</span><a href="http://www.scala-lang.org/docu/files/api/index.html"><span style="color: #99cc99;">List</span></a><span style="color: #e77801;">&#91;</span>T<span style="color: #e77801;">&#93;</span><span style="color: #e77801;">&#93;</span> <a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">forSome</span></a> <span style="color: #e77801;">&#123;</span> <a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">type</span></a> T <span style="color: #e77801;">&#125;</span> <span style="color: #a00000;">=</span> <a href="http://www.scala-lang.org/docu/files/api/index.html"><span style="color: #99cc99;">List</span></a><span style="color: #e77801;">&#40;</span><a href="http://www.scala-lang.org/docu/files/api/index.html"><span style="color: #99cc99;">List</span></a><span style="color: #e77801;">&#40;</span><span style="color: #f78811;">42</span><span style="color: #e77801;">&#41;</span><span style="color: #e77801;">&#41;</span>
<a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #009900;">val</span></a> w <span style="color: #a00000;">=</span> x <a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #000099;">match</span></a> <span style="color: #e77801;">&#123;</span> <a href="http://www.scala-lang.org/docu/files/ScalaReference.pdf"><span style="color: #000099;">case</span></a> y <span style="color: #a00000;">:</span> <a href="http://www.scala-lang.org/docu/files/api/index.html"><span style="color: #99cc99;">List</span></a><span style="color: #e77801;">&#91;</span><a href="http://www.scala-lang.org/docu/files/api/index.html"><span style="color: #99cc99;">List</span></a><span style="color: #e77801;">&#91;</span>u<span style="color: #e77801;">&#93;</span><span style="color: #e77801;">&#93;</span> <span style="color: #a00000;">=&gt;</span> <span style="color: #e77801;">&#40;</span><span style="color: #e77801;">&#40;</span>z <span style="color: #a00000;">:</span> u<span style="color: #e77801;">&#41;</span> <span style="color: #a00000;">=&gt;</span> z<span style="color: #e77801;">&#41;</span><span style="color: #e77801;">&#40;</span>y.<span style="color: #006600;">head</span>.<span style="color: #006600;">head</span><span style="color: #e77801;">&#41;</span> <span style="color: #e77801;">&#125;</span></pre>
</blockquote>
<p>In both cases it reports that it cannot find the type <code>u</code>.  In the second case, it could be attributed to erasure, as there is no way dynamically to guarantee that the contents of <code>List</code> are in turn also a <code>List</code>.  However, the first seems reasonable, so it should probably be reported as a bug.</p>
]]></content:encoded>
			<wfw:commentRss>http://existentialtype.net/2008/03/09/correction-on-existential-unpacking/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

