-
Notifications
You must be signed in to change notification settings - Fork 0
/
Plane.hs
40 lines (31 loc) · 1.02 KB
/
Plane.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses #-}
module Plane where
import ListZipper
import Universe
import Control.Comonad
import Data.Default
data Plane z = Plane (Zipper (Zipper z))
instance Universe Plane a where
left (Plane z) = Plane (fmap lzLeft z)
right (Plane z) = Plane (fmap lzRight z)
up (Plane z) = Plane (lzLeft z)
down (Plane z) = Plane (lzRight z)
instance (Default a) => Matrix Plane a where
fromMatrix m = Plane $ Zipper rzf (head w) (tail w ++ rzf)
where
w = (map (\l -> Zipper rf f (l ++ rf)) m)
f = def
rf = repeat f
zf = Zipper rf f rf
rzf = repeat zf
toMatrix (Plane (Zipper _ m d)) = toRow m : fmap toRow d
where
toRow (Zipper _ m r) = m:r
instance Functor Plane where
fmap f (Plane z) = Plane (fmap (fmap f) z)
instance Comonad Plane where
extract (Plane z) = lzRead . lzRead $ z
duplicate u =
Plane $ fmap
(\r -> Zipper (tail $ iterate left r) r (tail $ iterate right r))
(Zipper (tail $ iterate up u) u (tail $ iterate down u))