6 ms·
To be clear, here's the Haskell translation go content = let env = Env { file = Nothing, modified = [], line = 0, result = 0 } lines = sp
by tel 12y ago
To be clear, here's the Haskell translation
go content =
let env = Env { file = Nothing, modified = [], line = 0, result = 0 }
lines = split_lines content
env' = start env lines
in case reverse (result env') of
[] -> []
_ : results -> results
start env x = case x of
[] -> return ()
line : lines
| length line > 4 && take 3 line == "+++" ->
do header env line
modified env 0 lines
| otherwise ->
start env lines
- tel 12y agoOr, 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.