Post #2735433
2026-05-11 09:59 UTC
@byorgey@mathstodon.xyz I'm in two minds about whether I prefer `lzw2` above or `lzw3` below:
```
lzw3 :: (a->b->c) -> (b->c) -> (a->c) -> [a] -> [b] -> [c]
lzw3 f g h (x:xs) (y:ys) = f x y : lzw3 f g h xs ys
lzw3 f g h xs [] = map h xs
lzw3 f g h [] ys = map g ys
```
`lzw3` is more general (you can implement `lzw2` using it, and I think not vice versa), but at least in this case a bit clunkier to use:
```
conjugate' :: [Int] -> [Int]
conjugate' = foldr incr []
where incr n ms = lzw3 ($) id ($0) (replicate n succ) ms
```
Replies (1)
-
@jer_gib@functional.cafe 2026-05-11 10:10
@byorgey@mathstodon.xyz I guess `lzw3` is the more natural one. Given ``` data OneOrBoth a b = This a | That b | Those a b ``` then it is equivalently ``` lzw3 :: (OneOrBoth a b -> c) -> [a] -> [b] -> [c] ```