module Text.XHtml.BlockTable (
BlockTable,
single,
above,
beside,
getMatrix,
showsTable,
showTable,
) where
infixr 4 `beside`
infixr 3 `above`
instance (Show a) => Show (BlockTable a) where
showsPrec :: Int -> BlockTable a -> ShowS
showsPrec Int
_ = forall a. Show a => BlockTable a -> ShowS
showsTable
type TableI a = [[(a,(Int,Int))]] -> [[(a,(Int,Int))]]
data BlockTable a = Table (Int -> Int -> TableI a) Int Int
single :: a -> BlockTable a
single :: forall a. a -> BlockTable a
single a
a = forall a. (Int -> Int -> TableI a) -> Int -> Int -> BlockTable a
Table (\ Int
x Int
y [[(a, (Int, Int))]]
z -> [(a
a,(Int
xforall a. Num a => a -> a -> a
+Int
1,Int
yforall a. Num a => a -> a -> a
+Int
1))] forall a. a -> [a] -> [a]
: [[(a, (Int, Int))]]
z) Int
1 Int
1
above :: BlockTable a -> BlockTable a -> BlockTable a
beside :: BlockTable a -> BlockTable a -> BlockTable a
BlockTable a
t1 above :: forall a. BlockTable a -> BlockTable a -> BlockTable a
`above` BlockTable a
t2 = forall a. BlockTable a -> BlockTable a
trans (forall a b c.
BlockTable a
-> BlockTable b
-> (TableI a -> TableI b -> TableI c)
-> BlockTable c
combine (forall a. BlockTable a -> BlockTable a
trans BlockTable a
t1) (forall a. BlockTable a -> BlockTable a
trans BlockTable a
t2) forall b c a. (b -> c) -> (a -> b) -> a -> c
(.))
BlockTable a
t1 beside :: forall a. BlockTable a -> BlockTable a -> BlockTable a
`beside` BlockTable a
t2 = forall a b c.
BlockTable a
-> BlockTable b
-> (TableI a -> TableI b -> TableI c)
-> BlockTable c
combine BlockTable a
t1 BlockTable a
t2 (\ TableI a
lst1 TableI a
lst2 [[(a, (Int, Int))]]
r ->
let
beside' :: [[(a, (Int, Int))]] -> TableI a
beside' ([(a, (Int, Int))]
x:[[(a, (Int, Int))]]
xs) ([(a, (Int, Int))]
y:[[(a, (Int, Int))]]
ys) = ([(a, (Int, Int))]
x forall a. [a] -> [a] -> [a]
++ [(a, (Int, Int))]
y) forall a. a -> [a] -> [a]
: [[(a, (Int, Int))]] -> TableI a
beside' [[(a, (Int, Int))]]
xs [[(a, (Int, Int))]]
ys
beside' ([(a, (Int, Int))]
x:[[(a, (Int, Int))]]
xs) [] = [(a, (Int, Int))]
x forall a. a -> [a] -> [a]
: [[(a, (Int, Int))]]
xs forall a. [a] -> [a] -> [a]
++ [[(a, (Int, Int))]]
r
beside' [] ([(a, (Int, Int))]
y:[[(a, (Int, Int))]]
ys) = [(a, (Int, Int))]
y forall a. a -> [a] -> [a]
: [[(a, (Int, Int))]]
ys forall a. [a] -> [a] -> [a]
++ [[(a, (Int, Int))]]
r
beside' [] [] = [[(a, (Int, Int))]]
r
in
[[(a, (Int, Int))]] -> TableI a
beside' (TableI a
lst1 []) (TableI a
lst2 []))
trans :: BlockTable a -> BlockTable a
trans :: forall a. BlockTable a -> BlockTable a
trans (Table Int -> Int -> TableI a
f1 Int
x1 Int
y1) = forall a. (Int -> Int -> TableI a) -> Int -> Int -> BlockTable a
Table (forall a b c. (a -> b -> c) -> b -> a -> c
flip Int -> Int -> TableI a
f1) Int
y1 Int
x1
combine :: BlockTable a
-> BlockTable b
-> (TableI a -> TableI b -> TableI c)
-> BlockTable c
combine :: forall a b c.
BlockTable a
-> BlockTable b
-> (TableI a -> TableI b -> TableI c)
-> BlockTable c
combine (Table Int -> Int -> TableI a
f1 Int
x1 Int
y1) (Table Int -> Int -> TableI b
f2 Int
x2 Int
y2) TableI a -> TableI b -> TableI c
comb = forall a. (Int -> Int -> TableI a) -> Int -> Int -> BlockTable a
Table Int -> Int -> TableI c
new_fn (Int
x1forall a. Num a => a -> a -> a
+Int
x2) Int
max_y
where
max_y :: Int
max_y = forall a. Ord a => a -> a -> a
max Int
y1 Int
y2
new_fn :: Int -> Int -> TableI c
new_fn Int
x Int
y =
case forall a. Ord a => a -> a -> Ordering
compare Int
y1 Int
y2 of
Ordering
EQ -> TableI a -> TableI b -> TableI c
comb (Int -> Int -> TableI a
f1 Int
0 Int
y) (Int -> Int -> TableI b
f2 Int
x Int
y)
Ordering
GT -> TableI a -> TableI b -> TableI c
comb (Int -> Int -> TableI a
f1 Int
0 Int
y) (Int -> Int -> TableI b
f2 Int
x (Int
y forall a. Num a => a -> a -> a
+ Int
y1 forall a. Num a => a -> a -> a
- Int
y2))
Ordering
LT -> TableI a -> TableI b -> TableI c
comb (Int -> Int -> TableI a
f1 Int
0 (Int
y forall a. Num a => a -> a -> a
+ Int
y2 forall a. Num a => a -> a -> a
- Int
y1)) (Int -> Int -> TableI b
f2 Int
x Int
y)
getMatrix :: BlockTable a -> [[(a,(Int,Int))]]
getMatrix :: forall a. BlockTable a -> [[(a, (Int, Int))]]
getMatrix (Table Int -> Int -> TableI a
r Int
_ Int
_) = Int -> Int -> TableI a
r Int
0 Int
0 []
showsTable :: (Show a) => BlockTable a -> ShowS
showsTable :: forall a. Show a => BlockTable a -> ShowS
showsTable BlockTable a
table = forall a. Show a => a -> ShowS
shows (forall a. BlockTable a -> [[(a, (Int, Int))]]
getMatrix BlockTable a
table)
showTable :: (Show a) => BlockTable a -> String
showTable :: forall a. Show a => BlockTable a -> String
showTable BlockTable a
table = forall a. Show a => BlockTable a -> ShowS
showsTable BlockTable a
table String
""