| removeTrailing0s :: String -> String
|
| removeTrailing0s s =
|
| let (_, f) = foldr maybeSkip0 (False, id) s
|
| s' = f ""
|
| -- If a component is completely stripped (due to being all '0's)
|
| -- this will return "0".
|
| in if null s' then "0" else s'
|
|
|
| -- Does not skip if any non-zero char has been reached
|
| maybeSkip0 c (True , f) = (True , (c:) . f)
|
| maybeSkip0 '0' (False, f) = (False, f)
|
| maybeSkip0 c (False, f) = (True , (c:) . f)
|