7 ms·
a la Haskell: ;;reducing fn x->a->x ;;transducer fn (x->a->x)->(x->b->x)
by richhickey 12y ago
a la Haskell:
;;reducing fn
x->a->x
;;transducer fn
(x->a->x)->(x->b->x)
- mike_ivanov 12y agoSo there's some common ground between map, filter, flatmap, etc and these transducers allow you to compose those common-ground representations? I mean, you can define `map` as a callable chain of `(key-by #(true)) -> (map-apply fn) -> (filter-trues)` and `filter` as `(key-by predicate) -> (map-apply identity) -> (filter-trues)` where key-by, map-apply and filter-trues are some low-level primitives? Is that correct?
- richhickey 12y agoPrecisely the opposite - these functions compose because they are representation-free.
- zem 12y agoor, to steal ashley yakeley's marvellous quip, "every sufficiently well-documented lisp program contains an ML program in its comments" (:
- xmonkee 12y agolol
- FranklinChen 12y agoMore precisely: -- Left reduce type Reducer a r = r -> a -> r -- Here's where then rank-2 type is needed type Transducer a b = forall r . Reducer a r -> Reducer b r