Kevin,<br><br>Below is my attempt, which hopefully is bad enough to get this thread rolling for you. :)&nbsp; <br><br>It rotates the &#39;i&#39;th element &#39;n&#39; times by swapping the &#39;i&#39;th element with the element to its right &#39;n&#39; times.&nbsp; It looks horribly inefficient to me, but is fairly simple and only depends on the prelude.&nbsp; I think it ought to be possible to reduce this to a very simple function with no recursion and one strategic splitAt, but I&#39;ve run out of time to work more on it. :(
<br><br><span style="font-family: courier new,monospace;">rotate :: [a] -&gt; Int -&gt; Int -&gt; [a]</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">rotate xs i n = snd (iterate swap (i,xs) !! n)
</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">swap :: (Int, [a]) -&gt; (Int, [a])</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">swap (i,xs) </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp; | i == length xs - 1 = (0, last xs : init (tail xs) ++ [head xs])
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp; | otherwise&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = (i + 1, start ++ [right,left] ++ end)</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">&nbsp;&nbsp; where</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (start, left:right:end) = splitAt i xs</span><br><br>

-Greg<br><br><br><br><br><div><span class="gmail_quote">On 6/4/07, <b class="gmail_sendername">kevin birch</b> &lt;<a href="mailto:kbirch@pobox.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
kbirch@pobox.com</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div><div><span><div>On 火, 2007-6月-05, at 02:54, Greg Fitzgerald wrote:</div><br><blockquote type="cite"><font size="3"><span style="font-size: 11px;">&gt; rotating the fourth element 2 positions would result in: [1, 2, 4, 3, 5]
</span></font><br>Seems odd.&nbsp; Should that be [4,1,2,3,5]?<br><br></blockquote></span>Yes, I meant to use the 5 element in my second example.&nbsp; Sorry for the confusion.</div><div><span><br><blockquote type="cite">
<font size="3"><span style="font-size: 11px;"> &gt; Is there an idomatic way to handle both of these cases in a function?</span></font><br>Generally people like to see your attempt at a solution before giving the idomatic one so that they are sure it&#39;s not a homework question.&nbsp; What do you have so far? 
<br><br></blockquote></span>Yeah, I only wish I had gone to a school that would be forward thinking enough to each FP.&nbsp; ;-)</div><div><br></div><div>Here is my version:</div><div><br></div><div>rotate :: Array Integer Card -&gt; Integer -&gt; Integer -&gt; Array Integer Card
</div><div>rotate a i n</div><div>&nbsp; &nbsp; | i &lt;= u - n = a // [(i, a ! (i + 1)), (i + 1, a ! (i + 2)), (i + 2, a ! i)]</div><div>&nbsp; &nbsp; | otherwise = a // zip [l..u] (h ++ [a ! i] ++ filter (not . (== (a ! i))) t)</div><div>
&nbsp; &nbsp; where (l, u) = bounds a
</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (h, t) = splitAt (fromInteger ((i - u) + n)) $ elems a</div><div><br></div><div>This function is part of my implementation of the Solitaire encryption algorithm, so that is why I have the reference to a Card data type.&nbsp; This does what I want, and seems basically idiomatic, but perhaps it could be better.
</div><div><br></div><div>Thanks,</div><span><div>Kevin</div><br></span></div></blockquote></div><br>