Talk:Haskell/Zippers

From Wikibooks, the open-content textbooks collection

Jump to: navigation, search

One of sigfpe's comonad articles shows a simple zipper-like structure for lists. I think that would be a good way to introduce the idea. We don't have to take the comonad stuff, of course :-), but lists are simpler to think about than trees -- Kowey 14:19, 4 January 2007 (UTC)

[edit] Solutions to exercises

I came up with this; it compiles and seems right, but it's unclear how one would check it's right. --Gwern (contribs) 03:50, 23 February 2007 (UTC)

put :: a -> Node a -> Node a
put n (DeadEnd _) = DeadEnd n
put n (Passage _ a) = Passage n a
put n (Fork _ a b) = Fork n a b
get :: Node a -> a
get (Passage x _) = x
get (DeadEnd x) = x
get (Fork x _  _) = x
Yes, that's the intended solution. What do you mean with "how to check it's right?" -- apfeλmus 09:39, 20 February 2007 (UTC)
Exactly that. I mean, I took the type signatures, thought about it a little bit, fixed it until the compiled, but after that how do I know it really does what it is supposed to do? I have no data to really check it on. --Gwern (contribs) 01:54, 21 February 2007 (UTC)
Why do you need to check something if you can prove that it's correct? :) I think the problem is that the specification of put and get has been rather vague. I changed it, is it better now? -- apfeλmus 12:19, 22 February 2007 (UTC)
I think it looks better, though I'll go back and actually try it later. As for proofs, well, I'd need a proof that my proof is correct first. --Gwern (contribs) 03:50, 23 February 2007 (UTC)

[edit] retrieve

There's something wrong with this definition, I think. retrieve has the type Thread -> Node a -> Node a, which is to say it returns Node a, but get n has the type Node a -> a, so a is being returned where Node a is expected.

Oops, it's an error in the type signature. I corrected it to Thread -> Node a -> a
-- apfeλmus 09:39, 20 February 2007 (UTC)