[racket-dev] Is it possible to write `flatten' in TR?

From: Neil Toronto (neil.toronto at gmail.com)
Date: Tue Aug 7 14:58:07 EDT 2012

On 08/07/2012 12:52 PM, Prabhakar Ragde wrote:
> Neil wrote:
>> (define (flatten lst)
>>    (cond [(list? lst)  (append* ((inst map (Listof A) (Listof* A))
>>                                  flatten
>>                                  lst))]
>>          [else  (list lst)]))
> This version of flatten has quadratic worst-case running time. Is that
> an issue? A linear-time implementation is possible. Eli has a nice post
> somewhere about this. That would probably run into the same type issues
> (no better, no worse). --PR

Ah! I'll have to have a look at my `list-flatten' and `vector-flatten' 
that use a predicate to distinguish elements, to make sure they don't 
have this problem. Thanks for pointing it out!

Neil ⊥

Posted on the dev mailing list.