<?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; pattern matching</title>
	<atom:link href="http://existentialtype.net/tag/pattern-matching/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>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>

