Re:“Transducers” by Rich Hickey at Strange Loop [video]
by dragonwriter on Monday September 22, 2014 @05:26PM
(#8352747)
> But I think that we miss the point doing that. A transducer should be able to lead to a new reducer which use a different type to accumulate inputs.
So, instead of
type Transducer a b = (Reducer a r s) -> (Reducer b r s)
you have: type Transducer a b r r' = (Reducer a r s) -> (Reducer b r' s)
Or, most generally (adding in the ability to change not only the type of the accumulator but also the type of the final result): type Transducer a b r r' s s' = (Reducer a r s) -> (Reducer b r' s')
Leaving Haskell for OCaml I'm more comfortable with :
The type of taking is `int -> ('a, 'b, 'c) red -> ('a, int * 'b, 'c) red`. The former `b` accumulator state has been replaced by a pair `(int,b)` where a counter is used to track how much items have been taken so far. Yes this should be improved with early termination. But the key point I want to highlight is that wrapping all the transducers into a single general type may imply the use of some sort of existential type (to abstract away the accumulation type). This general type is furthermore useless for the system to check the compatibility of a reducers along a transducer chain.---
Another point I would like to say is that if transducers are undoubtedly an important and effective mean to build efficient transformation chains, they doesn't deserve to be pushed forward of conventional transformers (map, filter, take, ...) to which we are used for long.
Based on collection definition as something whose content is reducible, we can define the 'map' collection transformation on the basis of 'mapping' reducer transformation
So, we have the clarity of map/filter/reduce with the power of transducers.https://github.com/didier-wenzek/odist is a project where I started to implement these ideas some months ago. This transducer discussion will undoubtedly energize me to work again on the topic !