Hi Stephen,
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)
finite :: b -> (a -> Finite s a -> b) -> Finite s a -> b
finite b _ (Finite []) = b
finite _ f (Finite (x:xs)) = f x (Finite xs)
Then viewl can be defined anywhere,
viewl :: Finite s a -> Either () (a, Finite s a)
viewl = finite (Left ()) (Right . (,))
Why would you ever decrease the Peano numbers? It's just an upper bound, not an exact size.
/J
2010/10/13 Stephen Tetley <stephen.tetley@gmail.com>:
> Hi Jonas
>
> Thanks - I was meaning an equivalent to viewl on Data.Sequence, on plain lists:
>
> viewl :: [a] -> Either () (a,[a])
> viewl [] = Left ()
> viewl (x:xs) = Right (x,xs)
>
>
> It was a trick question because I can't see how you can do it without
> decrement on the Peano numbers.
>
> Best wishes
>
> Stephen
>