Post #2735415
2026-05-11 14:01 UTC
@byorgey@mathstodon.xyz @oantolin@mathstodon.xyz @das_g@chaos.social In fact, this recursion is a `concat` after an unfold. So it's also a list futumorphism:
```
futu :: (b -> Maybe ([a],b)) -> b -> [a]
futu g z = case g z of
Nothing -> []
Just (ys, z') -> ys ++ futu g z'
```
(Not stated is the requirement that the generated chunk `ys` should be nonempty, in order to guarantee progress. Alternatively one can make the body return `Maybe (a,[a],b)`, enforcing the requirement structurally.) Then we have:
```
conjugate :: [Int] -> [Int]
conjugate = futu strip where
strip [] = Nothing
strip ns = Just (replicate m (length ns), takeWhile (>0) [ n - m | n <- ns ])
where m = minimum ns
```
Replies (1)
-
@byorgey@mathstodon.xyz 2026-05-11 14:10
@jer_gib@functional.cafe Thanks! I'll definitely need to spend some time digesting this. Hopefully I can package everything into a nice blog post next week.