<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.0.4" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
	<title>Comments on: On static and dynamic typing, and corn tortillas</title>
	<link>http://dubroy.com/blog/2007/01/08/on-static-and-dynamic-typing-and-corn-tortillas/</link>
	<description>on programming, usability, and design; by Patrick Dubroy</description>
	<pubDate>Wed, 20 Aug 2008 13:43:49 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.0.4</generator>

	<item>
		<title>by: Greg Buchholz</title>
		<link>http://dubroy.com/blog/2007/01/08/on-static-and-dynamic-typing-and-corn-tortillas/#comment-23</link>
		<pubDate>Thu, 11 Jan 2007 23:13:14 +0000</pubDate>
		<guid>http://dubroy.com/blog/2007/01/08/on-static-and-dynamic-typing-and-corn-tortillas/#comment-23</guid>
					<description>&lt;p&gt;You get a compiler error.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>You get a compiler error.</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Patrick</title>
		<link>http://dubroy.com/blog/2007/01/08/on-static-and-dynamic-typing-and-corn-tortillas/#comment-21</link>
		<pubDate>Thu, 11 Jan 2007 21:23:14 +0000</pubDate>
		<guid>http://dubroy.com/blog/2007/01/08/on-static-and-dynamic-typing-and-corn-tortillas/#comment-21</guid>
					<description>&lt;p&gt;Ok, but in those examples, what happens if you instanitate a list&lt;myclass&gt;, where MyClass doesn't implement operator+?&lt;/myclass&gt;&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Ok, but in those examples, what happens if you instanitate a list<myclass>, where MyClass doesn&#8217;t implement operator+?</myclass></p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Greg Buchholz</title>
		<link>http://dubroy.com/blog/2007/01/08/on-static-and-dynamic-typing-and-corn-tortillas/#comment-20</link>
		<pubDate>Thu, 11 Jan 2007 16:04:41 +0000</pubDate>
		<guid>http://dubroy.com/blog/2007/01/08/on-static-and-dynamic-typing-and-corn-tortillas/#comment-20</guid>
					<description>&lt;p&gt;Here's a better operator+ for that example (now with angle brackets)...&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;pre&gt;
template&#60;class T&#62; T operator+(T a, T b)
{
   T out;
   transform(a.begin(),a.end(),b.begin(),back_inserter(out),
             p&#60;typename T::value_type&#62;);
   return out;
}

&lt;/pre&gt;&lt;/code&gt;&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Here&#8217;s a better operator+ for that example (now with angle brackets)&#8230;</p>
<p><code>
<pre>
template&lt;class T&gt; T operator+(T a, T b)
{
   T out;
   transform(a.begin(),a.end(),b.begin(),back_inserter(out),
             p&lt;typename T::value_type&gt;);
   return out;
}
</pre>
<p></code></p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Greg Buchholz</title>
		<link>http://dubroy.com/blog/2007/01/08/on-static-and-dynamic-typing-and-corn-tortillas/#comment-19</link>
		<pubDate>Thu, 11 Jan 2007 16:03:37 +0000</pubDate>
		<guid>http://dubroy.com/blog/2007/01/08/on-static-and-dynamic-typing-and-corn-tortillas/#comment-19</guid>
					<description>&lt;p&gt;Here's a better operator+ for that example...&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;pre&gt;
template T operator+(T a, T b)
{
   T out;
   transform(a.begin(),a.end(),b.begin(),back_inserter(out),
             p);
   return out;
}

&lt;/pre&gt;&lt;/code&gt;&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Here&#8217;s a better operator+ for that example&#8230;</p>
<p><code>
<pre>
template T operator+(T a, T b)
{
   T out;
   transform(a.begin(),a.end(),b.begin(),back_inserter(out),
             p);
   return out;
}
</pre>
<p></code></p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Greg Buchholz</title>
		<link>http://dubroy.com/blog/2007/01/08/on-static-and-dynamic-typing-and-corn-tortillas/#comment-18</link>
		<pubDate>Thu, 11 Jan 2007 03:23:01 +0000</pubDate>
		<guid>http://dubroy.com/blog/2007/01/08/on-static-and-dynamic-typing-and-corn-tortillas/#comment-18</guid>
					<description>&lt;p&gt;Here's the similar thing in C++ which will work with lists of doubles, lists of lists of ints, etc...&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;pre&gt;&lt;b&gt;#include&lt;/b&gt;&#60;iostream&#62;
&lt;b&gt;#include&lt;/b&gt;&#60;list&#62;
&lt;b&gt;#include&lt;/b&gt;&#60;iterator&#62;

&lt;b&gt;using&lt;/b&gt; &lt;b&gt;namespace&lt;/b&gt; std;

&lt;b&gt;template&lt;/b&gt;&#60;&lt;b&gt;class&lt;/b&gt; T&#62; T &lt;b&gt;p&lt;/b&gt;(T a, T b){ &lt;b&gt;return&lt;/b&gt; a+b; }
&lt;b&gt;template&lt;/b&gt;&#60;&lt;b&gt;class&lt;/b&gt; T&#62; list&#60;T&#62; &lt;b&gt;operator&lt;/b&gt;+(list&#60;T&#62; a, list&#60;T&#62; b)
{
   list&#60;T&#62; out;
   &lt;b&gt;transform&lt;/b&gt;(a.&lt;b&gt;begin&lt;/b&gt;(),a.&lt;b&gt;end&lt;/b&gt;(),b.&lt;b&gt;begin&lt;/b&gt;(),&lt;b&gt;back_inserter&lt;/b&gt;(out),p&#60;T&#62;);
   &lt;b&gt;return&lt;/b&gt; out;
}

int &lt;b&gt;main&lt;/b&gt;(int argc, char* argv[])
{
    double x[] = { 1.0, 2.0, 3.0};
    double y[] = {10.0,11.0,12.0};
    list&#60;double&#62; &lt;b&gt;a&lt;/b&gt;(x,x+&lt;b&gt;sizeof&lt;/b&gt;(x)/&lt;b&gt;sizeof&lt;/b&gt;(double));
    list&#60;double&#62; &lt;b&gt;b&lt;/b&gt;(y,y+&lt;b&gt;sizeof&lt;/b&gt;(y)/&lt;b&gt;sizeof&lt;/b&gt;(double));
    list&#60;double&#62; c;

    c = a+b;

    &lt;b&gt;copy&lt;/b&gt;(c.&lt;b&gt;begin&lt;/b&gt;(),c.&lt;b&gt;end&lt;/b&gt;(),ostream_iterator&#60;double&#62;(cout, "\n"));

    &lt;b&gt;return&lt;/b&gt; 0;
}
&lt;/pre&gt;

&lt;p&gt;&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Here&#8217;s the similar thing in C++ which will work with lists of doubles, lists of lists of ints, etc&#8230;</p>
<p><code></code></p>
<pre><b>#include</b>&lt;iostream&gt;
<b>#include</b>&lt;list&gt;
<b>#include</b>&lt;iterator&gt;

<b>using</b> <b>namespace</b> std;

<b>template</b>&lt;<b>class</b> T&gt; T <b>p</b>(T a, T b){ <b>return</b> a+b; }
<b>template</b>&lt;<b>class</b> T&gt; list&lt;T&gt; <b>operator</b>+(list&lt;T&gt; a, list&lt;T&gt; b)
{
   list&lt;T&gt; out;
   <b>transform</b>(a.<b>begin</b>(),a.<b>end</b>(),b.<b>begin</b>(),<b>back_inserter</b>(out),p&lt;T&gt;);
   <b>return</b> out;
}

int <b>main</b>(int argc, char* argv[])
{
    double x[] = { 1.0, 2.0, 3.0};
    double y[] = {10.0,11.0,12.0};
    list&lt;double&gt; <b>a</b>(x,x+<b>sizeof</b>(x)/<b>sizeof</b>(double));
    list&lt;double&gt; <b>b</b>(y,y+<b>sizeof</b>(y)/<b>sizeof</b>(double));
    list&lt;double&gt; c;

    c = a+b;

    <b>copy</b>(c.<b>begin</b>(),c.<b>end</b>(),ostream_iterator&lt;double&gt;(cout, &#8220;n&#8221;));

    <b>return</b> 0;
}
</pre>
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Patrick</title>
		<link>http://dubroy.com/blog/2007/01/08/on-static-and-dynamic-typing-and-corn-tortillas/#comment-17</link>
		<pubDate>Wed, 10 Jan 2007 17:58:53 +0000</pubDate>
		<guid>http://dubroy.com/blog/2007/01/08/on-static-and-dynamic-typing-and-corn-tortillas/#comment-17</guid>
					<description>&lt;p&gt;What I meant by type compatibility is that the compiler is able to determine that a type has a specific interface (in your example, that it understands the + operator) without any sort of explicit declaration.&lt;/p&gt;

&lt;p&gt;In short, your example is exactly what I meant. Thanks.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>What I meant by type compatibility is that the compiler is able to determine that a type has a specific interface (in your example, that it understands the + operator) without any sort of explicit declaration.</p>
<p>In short, your example is exactly what I meant. Thanks.</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Greg Buchholz</title>
		<link>http://dubroy.com/blog/2007/01/08/on-static-and-dynamic-typing-and-corn-tortillas/#comment-16</link>
		<pubDate>Wed, 10 Jan 2007 15:56:16 +0000</pubDate>
		<guid>http://dubroy.com/blog/2007/01/08/on-static-and-dynamic-typing-and-corn-tortillas/#comment-16</guid>
					<description>&lt;blockquote&gt;I assume you’re referring to type compatibility in those static type systems?&lt;/blockquote&gt;

&lt;p&gt;If by "type compatibility" you mean types that can substitute for one another &lt;em&gt;everywhere&lt;/em&gt;, then no.  In Haskell, for example, you can create a function...&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;pre&gt;
double x = x+x
&lt;/pre&gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;...which can be passed anything that understands the plus operator.  So lets make lists of numbers understand "plus"...&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;pre&gt;
instance Num a =&#62; Num [a] where (+) = zipWith (+)
&lt;/pre&gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;...now let's try it out at the REPL...&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;pre&gt;
$ ghci type_compat.hs 
   ___         ___ _
  / _ \ /\  /\/ __(_)
 / /_\// /_/ / /  &#124; &#124;      GHC Interactive, 6.6, for Haskell 98.
/ /_\\/ __  / /___&#124; &#124;      http://www.haskell.org/ghc/
\____/\/ /_/\____/&#124;_&#124;      Type :? for help.

Loading package base ... linking ... done.
[1 of 1] Compiling Main          ( type_compat.hs, interpreted )

Ok, modules loaded: Main.
*Main&#62; double 4.0
8.0
*Main&#62; double 42
84
*Main&#62; double [1,2,3]
[2,4,6]
*Main&#62;
&lt;/pre&gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;...so you can use floating point numbers and lists of integers in &lt;em&gt;some&lt;/em&gt; of the same places, but I don't think they'd be called compatible types.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<blockquote><p>I assume you’re referring to type compatibility in those static type systems?</p></blockquote>
<p>If by &#8220;type compatibility&#8221; you mean types that can substitute for one another <em>everywhere</em>, then no.  In Haskell, for example, you can create a function&#8230;</p>
<p><code>
<pre>
double x = x+x
</pre>
<p></code></p>
<p>&#8230;which can be passed anything that understands the plus operator.  So lets make lists of numbers understand &#8220;plus&#8221;&#8230;</p>
<p><code>
<pre>
instance Num a =&gt; Num [a] where (+) = zipWith (+)
</pre>
<p></code></p>
<p>&#8230;now let&#8217;s try it out at the REPL&#8230;</p>
<p><code>
<pre>
$ ghci type_compat.hs
   ___         ___ _
  / _  /  // __(_)
 / /_// /_/ / /  | |      GHC Interactive, 6.6, for Haskell 98.
/ /_\/ __  / /___| |      http://www.haskell.org/ghc/
____// /_/____/|_|      Type :? for help.

Loading package base ... linking ... done.
[1 of 1] Compiling Main          ( type_compat.hs, interpreted )

Ok, modules loaded: Main.
*Main&gt; double 4.0
8.0
*Main&gt; double 42
84
*Main&gt; double [1,2,3]
[2,4,6]
*Main&gt;
</pre>
<p></code></p>
<p>&#8230;so you can use floating point numbers and lists of integers in <em>some</em> of the same places, but I don&#8217;t think they&#8217;d be called compatible types.</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Patrick</title>
		<link>http://dubroy.com/blog/2007/01/08/on-static-and-dynamic-typing-and-corn-tortillas/#comment-15</link>
		<pubDate>Wed, 10 Jan 2007 04:13:55 +0000</pubDate>
		<guid>http://dubroy.com/blog/2007/01/08/on-static-and-dynamic-typing-and-corn-tortillas/#comment-15</guid>
					<description>&lt;p&gt;I assume you're referring to type compatibility in those static type systems?&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>I assume you&#8217;re referring to type compatibility in those static type systems?</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Greg Buchholz</title>
		<link>http://dubroy.com/blog/2007/01/08/on-static-and-dynamic-typing-and-corn-tortillas/#comment-14</link>
		<pubDate>Tue, 09 Jan 2007 22:00:53 +0000</pubDate>
		<guid>http://dubroy.com/blog/2007/01/08/on-static-and-dynamic-typing-and-corn-tortillas/#comment-14</guid>
					<description>&lt;blockquote&gt;In your C++ example, is the type of the function still checked statically?&lt;/blockquote&gt;

&lt;p&gt;Yes.  I don't think I've ever seen a formal definition of &lt;a href="http://en.wikipedia.org/wiki/Duck_typing" rel="nofollow"&gt;duck&lt;/a&gt; &lt;a href="http://mindview.net/WebLog/log-0052" rel="nofollow"&gt;typing&lt;/a&gt;, but C++ templates certainly allow you to treat anything that quacks and waddles as a duck, while still making sure your type mismatches are detected at compile time.  Same goes for Haskell, &lt;a href="http://clean.cs.ru.nl/" rel="nofollow"&gt;Clean&lt;/a&gt;, etc.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<blockquote><p>In your C++ example, is the type of the function still checked statically?</p></blockquote>
<p>Yes.  I don&#8217;t think I&#8217;ve ever seen a formal definition of <a href="http://en.wikipedia.org/wiki/Duck_typing" rel="nofollow">duck</a> <a href="http://mindview.net/WebLog/log-0052" rel="nofollow">typing</a>, but C++ templates certainly allow you to treat anything that quacks and waddles as a duck, while still making sure your type mismatches are detected at compile time.  Same goes for Haskell, <a href="http://clean.cs.ru.nl/" rel="nofollow">Clean</a>, etc.</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Patrick</title>
		<link>http://dubroy.com/blog/2007/01/08/on-static-and-dynamic-typing-and-corn-tortillas/#comment-13</link>
		<pubDate>Tue, 09 Jan 2007 21:14:42 +0000</pubDate>
		<guid>http://dubroy.com/blog/2007/01/08/on-static-and-dynamic-typing-and-corn-tortillas/#comment-13</guid>
					<description>&lt;p&gt;Thanks for the pointers. You're right, I should take a look at those languages. I have poked around with Haskell and OCaml, but only the tiniest bit.&lt;/p&gt;

&lt;p&gt;In your C++ example, is the type of the function still checked statically?&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Thanks for the pointers. You&#8217;re right, I should take a look at those languages. I have poked around with Haskell and OCaml, but only the tiniest bit.</p>
<p>In your C++ example, is the type of the function still checked statically?</p>
]]></content:encoded>
				</item>
</channel>
</rss>
