1 -----------------------------------------------------------------------------
2 -- TableClass : Class for combinators used in building 2D tables.
4 -- Copyright (c) 1999 Andy Gill
6 -- This module is distributed as Open Source software under the
7 -- Artistic License; see the file "Artistic" that is included
8 -- in the distribution for details.
9 -----------------------------------------------------------------------------
20 {----------------------------------------------------------------------------
21 These combinators can be used to build formated 2D tables.
22 The specific target useage is for HTML table generation.
23 ----------------------------------------------------------------------------
27 > table1 :: (Table t) => t String
28 > table1 = single "Hello" +-----+
30 This is a 1x1 cell +-----+
33 single :: (Table t) => a -> t a
35 So the cells can contain anything.
37 > table2 :: (Table t) => t String
38 > table2 = single "World" +-----+
43 > table3 :: (Table t) => t String
44 > table3 = table1 %-% table2 +-----%-----+
46 % is used to indicate +-----%-----+
50 > table4 :: (Table t) => t String
51 > table4 = table3 %/% table2 +-----+-----+
53 Notice the padding on the %%%%%%%%%%%%%
54 smaller (bottom) cell to |World |
55 force the table to be a +-----------+
58 > table5 :: (Table t) => t String
59 > table5 = table1 %-% table4 +-----%-----+-----+
61 Notice the padding on the | %-----+-----+
62 leftmost cell, again to | %World |
63 force the table to be a +-----%-----------+
66 Now the table can be rendered with processTable, for example:
67 Main> processTable table5
71 [("World",(2,1))]] :: [[([Char],(Int,Int))]]
74 ----------------------------------------------------------------------------}
77 -- There are no empty tables
79 --Single element table
81 -- horizontal composition
82 beside :: t a -> t a -> t a
83 -- vertical composition
84 above :: t a -> t a -> t a
85 -- generation of raw table matrix
86 getMatrix :: t a -> [[(a,(Int,Int))]]
88 showsTable :: (Show a,Table t) => t a -> ShowS
89 showsTable table = shows (getMatrix table)
91 showTable :: (Show a,Table t) => t a -> String
92 showTable table = showsTable table ""