[Haskell-beginners] Brainfuck interpreter stack overflow

Felipe Lessa felipe.lessa at gmail.com
Tue Jan 26 14:49:29 EST 2010

On Tue, Jan 26, 2010 at 05:06:25PM +0100, Edgar Klerks wrote:
>  I also have another question about deriving monads. I have modified
> Data.List.Zipper, so it supports 2 extra directions (up and down):
> data ZipperQuad a = Zip [a] [a] [a] [a]

(I've changed the name to ZipperQuad.)

How do you go up and down? If say that

  up :: ZipperQuad a -> ZipperQuad a
  up (Zip ls rs ds (u:us)) = Zip ls rs (u:ds) us
  up z                     = z

then your new zipper is isomorphic to two old zippers

  data ZipperQuad' a = Z4 !(Zipper a) !(Zipper a)

with functions

  up,down,left4,right4 :: ZipperQuad' a -> ZipperQuad' a
  up     (Z4 h v) = Z4 h (right v)
  down   (Z4 h v) = Z4 h (left v)
  left4  (Z4 h v) = Z4 (left h) v
  right4 (Z4 h v) = Z4 (right h) v

Wouldn't a really fair ZipperQuad walk on a grid?


More information about the Beginners mailing list