diff options
author | Edoardo La Greca | 2025-09-09 20:38:00 +0200 |
---|---|---|
committer | Edoardo La Greca | 2025-09-09 20:38:00 +0200 |
commit | f46dafc461e4ee3fa1637051284f89b443f00a51 (patch) | |
tree | bfc6b3aebbe12141d34b9727e11766bffdc2937e /lec07/Buffer.hs | |
parent | 476ae2fe83ea46e3845b0c32afe7df57c8fb109b (diff) |
add files for lecture 7's homework
Diffstat (limited to 'lec07/Buffer.hs')
-rw-r--r-- | lec07/Buffer.hs | 28 |
1 files changed, 28 insertions, 0 deletions
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 |