<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Erlang Programming Exercise: 3-5 (refactor)</title>
	<atom:link href="http://benjaminhalsted.com/2010/03/erlang-programming-exercise-3-5-refactor/feed/" rel="self" type="application/rss+xml" />
	<link>http://benjaminhalsted.com/2010/03/erlang-programming-exercise-3-5-refactor/</link>
	<description>// [bgh] todo, add something clever here.</description>
	<lastBuildDate>Wed, 09 Mar 2011 02:11:50 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
	<item>
		<title>By: Sergey Shelukhin</title>
		<link>http://benjaminhalsted.com/2010/03/erlang-programming-exercise-3-5-refactor/comment-page-1/#comment-588</link>
		<dc:creator>Sergey Shelukhin</dc:creator>
		<pubDate>Sun, 13 Feb 2011 21:31:16 +0000</pubDate>
		<guid isPermaLink="false">http://benjaminhalsted.com/?p=136#comment-588</guid>
		<description>With restriction of using concatenate very similar function can be written:

flatten2(List) -&gt; reverse( flatten_helper(List,[]) ).
flatten_helper([],Dst) -&gt; Dst;
flatten_helper([H&#124;T],Dst) when is_list(H) -&gt; flatten_helper( concatenate([H,T]), Dst );
flatten_helper([H&#124;T],Dst) -&gt;  flatten_helper( T, [H&#124;Dst] ).

you could avoid is_list by matching [[HH&#124;HT]&#124;T] and [[]&#124;T] separately as in your example.

I am now trying to break it :)</description>
		<content:encoded><![CDATA[<p>With restriction of using concatenate very similar function can be written:</p>
<p>flatten2(List) -&gt; reverse( flatten_helper(List,[]) ).<br />
flatten_helper([],Dst) -&gt; Dst;<br />
flatten_helper([H|T],Dst) when is_list(H) -&gt; flatten_helper( concatenate([H,T]), Dst );<br />
flatten_helper([H|T],Dst) -&gt;  flatten_helper( T, [H|Dst] ).</p>
<p>you could avoid is_list by matching [[HH|HT]|T] and [[]|T] separately as in your example.</p>
<p>I am now trying to break it <img src='http://benjaminhalsted.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nate Kidwell</title>
		<link>http://benjaminhalsted.com/2010/03/erlang-programming-exercise-3-5-refactor/comment-page-1/#comment-547</link>
		<dc:creator>Nate Kidwell</dc:creator>
		<pubDate>Sat, 20 Nov 2010 18:18:03 +0000</pubDate>
		<guid isPermaLink="false">http://benjaminhalsted.com/?p=136#comment-547</guid>
		<description>Heya-

Found your blog while doing the exercises and searching for the answer to a question I had about 3.5 (writing flatten).  Basically it says to use &quot;concatenate to solve flatten&quot; and even though I solved flatten similarly to the first way you did (my code below), I also didn&#039;t use concatenate. 

What I&#039;m OCDing on is I actually think his hint on using concatenate is wrong here, because erlang&#039;s lists are untyped (so you never know if your dealing with a list of lists (which is what concatenate takes) until you navigate it).

Regardless, great blog, and I&#039;m going to start following your solutions to his book.

************************

flatten([], Accum) -&gt;
	Accum;
flatten([H&#124;[]], Accum) -&gt;
	flatten(H, Accum);
flatten([H&#124;T], Accum) -&gt;
	flatten(H, flatten(T, Accum));
flatten(Val, Accum) -&gt;
	[Val &#124; Accum].

flatten(List)	-&gt;
	flatten(List,[]).</description>
		<content:encoded><![CDATA[<p>Heya-</p>
<p>Found your blog while doing the exercises and searching for the answer to a question I had about 3.5 (writing flatten).  Basically it says to use &#8220;concatenate to solve flatten&#8221; and even though I solved flatten similarly to the first way you did (my code below), I also didn&#8217;t use concatenate. </p>
<p>What I&#8217;m OCDing on is I actually think his hint on using concatenate is wrong here, because erlang&#8217;s lists are untyped (so you never know if your dealing with a list of lists (which is what concatenate takes) until you navigate it).</p>
<p>Regardless, great blog, and I&#8217;m going to start following your solutions to his book.</p>
<p>************************</p>
<p>flatten([], Accum) -&gt;<br />
	Accum;<br />
flatten([H|[]], Accum) -&gt;<br />
	flatten(H, Accum);<br />
flatten([H|T], Accum) -&gt;<br />
	flatten(H, flatten(T, Accum));<br />
flatten(Val, Accum) -&gt;<br />
	[Val | Accum].</p>
<p>flatten(List)	-&gt;<br />
	flatten(List,[]).</p>
]]></content:encoded>
	</item>
</channel>
</rss>

