haskell
haskell copied to clipboard
Series exercise requires strange edge case handling
The test cases for the Series exercises require that
series 0 [] = [[]]
series _ [] = []
This seems counterintuitive and is not documented in the problem description. Is there a reason why the test cases were chosen like this?
For series n xs, you would expect that length (series n xs) == min 0 (length xs - n + 1)
If n == 0 and length xs == 0, then length (series n xs) should be 0 - 0 + 1 == 1. This tells us that there is one way to make a series of length 0 from the empty series: the empty series.
If n == 1 and length xs == 0, then length (series n xs) should be 0 - 1 + 1 == 0. This tells us that the empty series contains no series of length 1.
If n == 2 and length xs == 0, then length (series n xs) should be 0 because 0 - 2 + 1 < 0. This too tells us that the empty series contains no series of length 2.
I'm not sure I feel particularly great about the test cases with n == 0 though. They could all be removed, but then someone would just suggest we add them again.
It's probably better to pick exactly one of these two options:
- Declare that
n == 0is an error. ThereforeseriesbeInt -> String -> Maybe [[Int]], and the result forn == 0should beNothing. - Make the description better by submitting a pull request for https://github.com/exercism/problem-specifications/blob/main/exercises/series/description.md