HN user

jaredtobin

212 karma

https://jtobin.io

[ my public key: https://keybase.io/jtobin; my proof: https://keybase.io/jtobin/sigs/-hjJrUjcY3D4mJ-dbSuLxojYWSdAFBMzin1dUcvg4Ck ]

Posts7
Comments7
View on HN

It's exactly a hylomorphism. Here's a possibly more familiar-looking Haskell form:

    {-# LANGUAGE DeriveFunctor #-}
    {-# LANGUAGE LambdaCase #-}

    import Data.Functor.Foldable
    import Data.List.Split

    data QuadTreeF a r =
        NodeF r r r r
      | LeafF a
      | EmptyF
      deriving Functor

    builder :: [a] -> QuadTreeF a [a]
    builder = \case
      []  -> EmptyF
      [x] -> LeafF x
      xs  -> NodeF a b c d where
        [a, b, c, d] = chunksOf (length xs `div` 4) xs

    consumer :: QuadTreeF a [a] -> [a]
    consumer = \case
      EmptyF            -> []
      LeafF a           -> [a]
      NodeF ul ur lr ll -> concat [ll, ul, ur, lr]

    rotate :: [a] -> [a]
    rotate = hylo consumer builder

Discussions on this kind of thing probably largely settle into opposing "yay Soylent!" and "boo Soylent!" sides. When I look at this as a tidbit of news, however, it doesn't seem to say very much to me.

"Small percentage of consumers report dissatisfaction with product - company investigating."