Earlier quoted context omitted.
Don't overthink it. But if we're gonna overthink it, one thing we can notice is that a rose tree is a free monad, and like any free structure is initial in its category - meaning there's a unique monad homomorphism from a rose tree to any other monad. Lists form a monad, so we can ask "what is that homomorphism?" It turns out to be the traditional definition of flatten. That is to say, only flatten solves these equat…
I believe speaking of monads, monoids, functors, and homomorphism when discussing an interview question for fairly fresh programmers is definitely overthinking it. I'm not sure what you think is so simple about your solution compared to: sub flatten { map { ref ? flatten( @$_ ) : $_ } @_; } Goodness, and Perl gets a bad reputation for the amount of punctuation in the code. Of course if you want flatten in Haskell you…
I agree. I said as much. I just thought it was interesting.
> I'm not sure what you think is so simple about your solution compared to [...]
Which solution? I didn't present an implementation in this thread. I did elsewhere (https://news.ycombinator.com/item?id=13726564), but I don't think that's what you're talking about? I was discussing specification, and the code fragment in my comment was a property, not a definition.
> Of course if you want flatten in Haskell you have it for Tree and Forest.
Yes, though Tree is a slightly less natural choice for this than a rose tree (aka `Free []`). Of course, you still have it (in the form of toList).
> If a Perl programmer wanted to pull in a CPAN module, there are many from which to choose. Of course, it was just done in a one-line subroutine.
... yes?
You seem to be desperately trying to defend perl against an attack you imagine me to have made. I have nothing against perl (at least, nothing beyond a strong desire for static types on large projects, but that applies equally to a great many languages).