Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

My Haskell reading is weak, but that looks like it would change the order of elements in the 2 lists, as you are prepending items to the front of `trues` and `falses`, instead of "appending" them. Of course `append` is forbidden, because it is linear runtime itself.

I just checked my code and while I think the partition example still shows the problem, the problem I used to check is a similar one, but different one:

Split a list at an element that satisfies a predicate. Here is some code for that in Scheme:

    (define split-at
        (λ (lst pred)
          "Each element of LST is checked using the predicate. If the
    predicate is satisfied for an element, then that element
    will be seen as the separator. Return 2 values: The split
    off part and the remaining part of the list LST."
          (let iter ([lst° lst]
                     [index° 0]
                     [cont
                      (λ (acc-split-off rem-lst)
                        (values acc-split-off rem-lst))])
            (cond
             [(null? lst°)
              (cont '() lst°)]
             [(pred (car lst°) index°)
              (cont '() (cdr lst°))]
             [else
              (iter (cdr lst°)
                    (+ index° 1)
                    (λ (new-tail rem-lst)
                      (cont (cons (car lst°) new-tail)
                            rem-lst)))]))))
For this kind of stuff with constructed continuations they somehow never get it. They will do `reverse` and `list->vector`, and `append` all day long or some other attempt of working around what you specify they shall not do. The concept of building up a continuation seems completely unknown to them.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: