Fun exercise: Write a Haskell function update :: Tree a → [a] → Maybe (Tree a), that updates the leaves of a Tree by those given in a list (if there are not enough, return Nothing). My attempt after CW

pop :: Compose (State [a]) Maybe a
pop = Compose $do xs <- get modify' (drop 1) pure (listToMaybe xs) update = evalState . getCompose . go where go (Node _ []) = pure <$> pop
go (Node x ts) = Node x <\$> traverse go ts

· · Web · · ·

I wrote a post on my blog detailing how to come up with this solution codual.github.io/2019/07/03/tr

The social network of the future: No ads, no corporate surveillance, ethical design, and decentralization! Own your data with Mastodon!