From f46dafc461e4ee3fa1637051284f89b443f00a51 Mon Sep 17 00:00:00 2001 From: Edoardo La Greca Date: Tue, 9 Sep 2025 20:38:00 +0200 Subject: add files for lecture 7's homework --- lec07/Buffer.hs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 lec07/Buffer.hs (limited to 'lec07/Buffer.hs') diff --git a/lec07/Buffer.hs b/lec07/Buffer.hs new file mode 100644 index 0000000..6eb55af --- /dev/null +++ b/lec07/Buffer.hs @@ -0,0 +1,28 @@ +module Buffer where + +-- Type class for data structures that can represent the text buffer +-- of an editor. + +class Buffer b where + + -- | Convert a buffer to a String. + toString :: b -> String + + -- | Create a buffer from a String. + fromString :: String -> b + + -- | Extract the nth line (0-indexed) from a buffer. Return Nothing + -- for out-of-bounds indices. + line :: Int -> b -> Maybe String + + -- | @replaceLine n ln buf@ returns a modified version of @buf@, + -- with the @n@th line replaced by @ln@. If the index is + -- out-of-bounds, the buffer should be returned unmodified. + replaceLine :: Int -> String -> b -> b + + -- | Compute the number of lines in the buffer. + numLines :: b -> Int + + -- | Compute the value of the buffer, i.e. the amount someone would + -- be paid for publishing the contents of the buffer. + value :: b -> Int -- cgit v1.2.3