Hacker News new | past | comments | ask | show | jobs | submit login

> How would you write a function parameter that takes two arguments, whose type is determined by the seed argument?

I feel like I'm missing something here. I would think it would just be

    reduce<I, O>(fn:(O, I|O)=>O, seed:I): O



How would you call it? I'm interested in how you'd specify `I` and `O`.

`I` is obviously a string, but it seems like `O` needs to be at least three different types:

  > (reduce (fn (x y)
              (list x y))
            (list "a"))
  "a"
  > (reduce (fn (x y)
              (list x y))
            (list "a" "b"))
  ("a" "b")
  > (reduce (fn (x y)
              (list x y))
            (list "a" "b" "c"))
  ("a" ("b" "c"))


`O` would be whatever the type of the reducer is, so for `list` in the lisp you're using (is it Clojure? The function params look wrong) has a type signature `(A, B?, ...Z?) -> A | List(A, B, ...Z)`.

So the transducer in this case would have the type `List(A, B?, ...Z?) -> A | List(A, B | List(B, ...etc))`

It's not three different types, but it is necessarily recursive, which seems tricky.




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

Search: