3 ms·
Or, slightly differently, start probably should have been start env x = case x of [] -> env line : lines | length line > 4 && take 3 l
by tel 12y ago
Or, slightly differently, start probably should have been
start env x = case x of
[] -> env
line : lines
| length line > 4 && take 3 line == "+++" ->
modified (header env line) 0 lines
| otherwise ->
start env lines
This reflects the pure functional style over the state monad mechanism I half implemented above. OCaml is just using normal mutability.
- masklinn 12y agoIs there any reason for using a case instead of start env [] = env start env (line:lines) | length line > 4 && take 3 line == "+++" = modified (header env line) 0 lines | otherwise = start env lines ? or even start env [] = env start env (line@('+':'+':'+':_:_):lines) = modified (header env line) 0 lines start env (_:lines) = start env lines ?
- tel 12y agoThe first one is basically identical. The second one I probably wouldn't do. In both cases it just comes down to style though.