Hi Stephen,<br><br>I'm not sure I see the problem. You can do what you require with the function i supplied (minus the typo). This is in the module (where the Finite constructor is exposed)<br><br><span style="font-family: courier new,monospace;">finite :: b -> (a -> Finite s a -> b) -> Finite s a -> b</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">finite b _ (Finite []) = b</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">finite _ f (Finite (x:xs)) = f x (Finite xs)</span><br>
<br>Then viewl can be defined anywhere,<br><br><span style="font-family: courier new,monospace;">viewl :: Finite s a -> Either () (a, Finite s a)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">viewl = finite (Left ()) (Right . (,))</span><br>
<br>Why would you ever decrease the Peano numbers? It's just an upper bound, not an exact size.<br><br>/J<br><br>2010/10/13 Stephen Tetley <<a href="mailto:stephen.tetley@gmail.com">stephen.tetley@gmail.com</a>>:<br>
> Hi Jonas<br>><br>> Thanks - I was meaning an equivalent to viewl on Data.Sequence, on plain lists:<br>><br>> viewl :: [a] -> Either () (a,[a])<br>> viewl [] = Left ()<br>> viewl (x:xs) = Right (x,xs)<br>
><br>><br>> It was a trick question because I can't see how you can do it without<br>> decrement on the Peano numbers.<br>><br>> Best wishes<br>><br>> Stephen<br>><br><br>