[Haskell-beginners] Just clarifying the "pred" and "succ"
functions in Haskell
Andy Elvey
andy.elvey at paradise.net.nz
Sat Feb 6 15:45:14 EST 2010
Felipe Lessa wrote:
(snip )
>
> Although we can't have a pointer to the middle of a list [a], we
> can have another data struture that behaves sort of as if we had
> that pointer: a zipper. For example,
>
> http://hackage.haskell.org/packages/archive/ListZipper/1.1.1.0/doc/html/Data-List-Zipper.html
>
> To understand a list zipper you could think of it as something like
>
> struct zipper {
> list left, right;
> }
>
> So we track our "position" by tracking what's on the left and
> what's on the right. By using the API of the link above you
> could have something similar to what you wanted:
>
> lpred :: Zipper a -> a
> lpred = focus . left
>
> lsucc :: Zipper a -> a
> lsucc = focus . right
>
> --
> Felipe.
>
Hi Felipe -
Thanks very much for that! That's very handy to know. I think that
I'll base my lpred and lsucc on this approach.
Bye for now -
- Andy
More information about the Beginners
mailing list