]> git.rkrishnan.org Git - yorgey.git/blob - hw7/Buffer.hs
hw7: starting materials
[yorgey.git] / hw7 / Buffer.hs
1 module Buffer where
2
3 -- Type class for data structures that can represent the text buffer
4 -- of an editor.
5
6 class Buffer b where
7
8   -- | Convert a buffer to a String.
9   toString :: b -> String
10
11   -- | Create a buffer from a String.
12   fromString :: String -> b
13
14   -- | Extract the nth line (0-indexed) from a buffer.  Return Nothing
15   -- for out-of-bounds indices.
16   line :: Int -> b -> Maybe String
17
18   -- | @replaceLine n ln buf@ returns a modified version of @buf@,
19   --   with the @n@th line replaced by @ln@.  If the index is
20   --   out-of-bounds, the buffer should be returned unmodified.
21   replaceLine :: Int -> String -> b -> b
22
23   -- | Compute the number of lines in the buffer.
24   numLines :: b -> Int
25
26   -- | Compute the value of the buffer, i.e. the amount someone would
27   --   be paid for publishing the contents of the buffer.
28   value :: b -> Int