[Haskell-cafe] What's wrong in my Data.Generic.Zipper code?

Martijn Schrage martijn at oblomov.com
Sun Jul 10 21:37:38 UTC 2016


On 10 juli 2016 at 20:03:57, martin (martin.drautzburg at web.de) wrote:

Am 07/10/2016 um 03:17 PM schrieb Martijn Schrage:
> Hi Martin,
>
> Ghci defaults the type of 'getHole t1' to 'Maybe ()'. You can see this
happening if you enable warnings in ghci with
> ':set -Wall'. Providing the correct type signature gives you the answer
you're expecting:
>
> *Main> getHole t1 :: Maybe [Int]
> Just [1,2,3]

I understand, thanks.

I tried a generic Zipper with a pair and noticed that going down gives me
the second component. This does make some
sense, but I am still having trouble to anticipate what up, down, left and
right do when the the datatype is more
complicated and not a tree. E.g. this one gives me trouble:

import qualified Data.Sequence as S


To understand the navigation, just draw your values as trees, with the
constructor on one level and the children below. For example, a list [1,2]
becomes:

  (:)
 /   \
1    (:)
    /   \
   2     []

And a tuple (1,2) becomes:

    (,)
   /   \
  1     2

Also note that down not only moves a level downward, but also to the
rightmost child (down' moves to the leftmost child instead).

I'm not sure how useful it is to use a zipper on a Seq (which, as you can
see in the source, is still just a tree, like all data types,) as the
implementation uses a balanced FingerTree which is kept abstract. But as it
turns out, the Seq Data instance follows the right-associative view
pattern, so if you wish you could navigate similar to lists (down for the
tail, and down' or down followed by left for the head).

Cheers,
Martijn


data Items lbl = Items (S.Seq (lbl, Items lbl))
deriving (Eq, Show, Typeable, Data)


Is there an easy way to understinfing those moves?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20160710/a1aae5ff/attachment.html>


More information about the Haskell-Cafe mailing list