• This is actually best practice rather than clever (ok maybe clever) cuz it's O(1).

  • You should lookup what infix operators other than composition are provided in prelude.

  • Well, I just can't manage it!

    Are you supposed to make this pointfree or not, I wonder... I'm a character off, and nothing I try does it.

  • Could really do with more rigorous testing.

  • I'd allow one extra character for at least some variability in possible solutions, and they would still require firm grasp of the concept

  • They do not conflict, the second function is simply more general then the first one. Try to squeeze in one more type variable into your definition.

  • What's the type of foldRoseTree? According to the simple test cases I implemented the foldRoseTree with type (a -> [b] -> b) -> (b -> [b] -> [b]) -> [b] -> RoseTree a -> b, but there is a function roseDepth = foldRoseTree (const (+ 1)) max 0 in truly test cases, which is conflict with simple test cases.

  • I guess for now.

  • I can constraint type signature of scanl and check inside what exactly is passed to it, the only thing is it will break almost all solutions, is it fine?

  • Oh yeah, foldr also assumes the fold is associative.

    Speaking of that, you should add some random tests and more complicated fixed tests. You can use QuickCheck to help you with the random tests ;-)

  • ghci> leafTree
          (LeafLeaf 1) 
          (LeafLeaf 2)) 
        (LeafLeaf 3)) 
      (LeafLeaf 4)
    ghci> appEndo (foldMap (Endo . LeafNode) (fmap LeafLeaf leafTree)) (LeafLeaf 10) -- some random base case
      (LeafLeaf 1) 
        (LeafLeaf 2) 
          (LeafLeaf 3) 
            (LeafLeaf 4) 
            (LeafLeaf 10))))
  • Oh, nice, thank you! Your solution only passed because of my poorly written tests (which I hope I fixed by now). The thing is you get a bunch of Endo . LeafNode combined one after another (as if we had a list), instead of our previous proper structure.

    Here what base says about it:

    For a general Foldable structure this should be semantically identical to,
    foldr f z = foldr f z . toList

  • Updated.

  • Also, the 3 functions to be completed should be in reversed order, since ideally the difficulty should be paced from easier to harder ones, which currently seems to be in the opposite order instead. You might need to change the order of the tests too.

  • Loading more items...