[Haskell-cafe] Finite but not fixed length...
Jonas Almström Duregård
jonas.duregard at chalmers.se
Wed Oct 13 13:33:47 EDT 2010
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.
2010/10/13 Stephen Tetley <stephen.tetley at gmail.com>:
> Hi Jonas
> Thanks - I was meaning an equivalent to viewl on Data.Sequence, on plain
> 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
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe