[Haskell-cafe] Finite but not fixed length...
Jonas Almström Duregård
jonas.duregard at chalmers.se
Wed Oct 13 13:37:09 EDT 2010
>Then viewl can be defined anywhere,
>
>viewl :: Finite s a -> Either () (a, Finite s a)
>viewl = finite (Left ()) (Right . (,))
... or more like:
viewl :: Finite s a -> Either () (a, Finite s a)
viewl = finite (Left ()) (\a b -> Right (a,b))
/J
2010/10/13 Jonas Almström Duregård <jonas.duregard at chalmers.se>
> 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 at 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
> >
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20101013/d8aa0b2e/attachment.html
More information about the Haskell-Cafe
mailing list