Type-safe Transducers in Clojure, Scala, and Haskell
blog.podsnap.com
Type-safe Transducers in Clojure, Scala, and Haskell
1–10 of 13 posts
Re: Type-safe Transducers in Clojure, Scala, and Haskell
#2[1] https://github.com/clojure/clojure/blob/b01adb859c66322c5cff...
[2] https://github.com/clojure/clojure/blob/b01adb859c66322c5cff...
Re: Type-safe Transducers in Clojure, Scala, and Haskell
#3Re: Type-safe Transducers in Clojure, Scala, and Haskell
#4This is interesting, but it's still missing some very important features of transducers. As you alluded, stateful operations [1] won't work at all in your Haskell model. Also, you've missed early termination [2], which Rich's talk [3] covered well. [1] https://github.com/clojure/clojure/blob/b01adb859c66322c5cff... [2] https://github.com/clojure/clojure/blob/b01adb859c66322c5cff... [3] https://www.youtube.com/watch?v…
Couldn't you just parametrize over IO/ST/etc.? E.g. something like
IO r -> a -> IO r
I don't have a great mental model of transducers yet, so I'm not confident about that.Re: Type-safe Transducers in Clojure, Scala, and Haskell
#5This is interesting, but it's still missing some very important features of transducers. As you alluded, stateful operations [1] won't work at all in your Haskell model. Also, you've missed early termination [2], which Rich's talk [3] covered well. [1] https://github.com/clojure/clojure/blob/b01adb859c66322c5cff... [2] https://github.com/clojure/clojure/blob/b01adb859c66322c5cff... [3] https://www.youtube.com/watch?v…
>As you alluded, stateful operations [1] won't work at all in your Haskell model. Couldn't you just parametrize over IO/ST/etc.? E.g. something like IO r -> a -> IO r I don't have a great mental model of transducers yet, so I'm not confident about that.
Re: Type-safe Transducers in Clojure, Scala, and Haskell
#6This line made me laugh out loud: "... whenever something is even slightly ugly in Scala, you introduce an implicit to make it confusing instead."
Re: Type-safe Transducers in Clojure, Scala, and Haskell
#7Earlier quoted context omitted.
>As you alluded, stateful operations [1] won't work at all in your Haskell model. Couldn't you just parametrize over IO/ST/etc.? E.g. something like IO r -> a -> IO r I don't have a great mental model of transducers yet, so I'm not confident about that.
You can do that, but it's more elegant if you define a functional stateful transducer analogous to scanl for lists.
Re: Type-safe Transducers in Clojure, Scala, and Haskell
#8Earlier quoted context omitted.
>As you alluded, stateful operations [1] won't work at all in your Haskell model. Couldn't you just parametrize over IO/ST/etc.? E.g. something like IO r -> a -> IO r I don't have a great mental model of transducers yet, so I'm not confident about that.
You can do that, but it's more elegant if you define a functional stateful transducer analogous to scanl for lists.
Re: Type-safe Transducers in Clojure, Scala, and Haskell
#9This is interesting, but it's still missing some very important features of transducers. As you alluded, stateful operations [1] won't work at all in your Haskell model. Also, you've missed early termination [2], which Rich's talk [3] covered well. [1] https://github.com/clojure/clojure/blob/b01adb859c66322c5cff... [2] https://github.com/clojure/clojure/blob/b01adb859c66322c5cff... [3] https://www.youtube.com/watch?v…
Re: Type-safe Transducers in Clojure, Scala, and Haskell
#10This is interesting, but it's still missing some very important features of transducers. As you alluded, stateful operations [1] won't work at all in your Haskell model. Also, you've missed early termination [2], which Rich's talk [3] covered well. [1] https://github.com/clojure/clojure/blob/b01adb859c66322c5cff... [2] https://github.com/clojure/clojure/blob/b01adb859c66322c5cff... [3] https://www.youtube.com/watch?v…
>As you alluded, stateful operations [1] won't work at all in your Haskell model. Couldn't you just parametrize over IO/ST/etc.? E.g. something like IO r -> a -> IO r I don't have a great mental model of transducers yet, so I'm not confident about that.
data Fold i o = forall st . Fold
{ merge :: st -> i -> st
, this :: st
, view :: st -> o
}
type (i ~> o) = forall r . Fold o r -> Fold i r
-- compare
type Trans i o = forall r . (r -> o -> r) -> (r -> i -> r)
Now each "step" has local pure state and no other step can break abstraction barriers and view it. This also gives you all of the effects of the indexed state passing Rich called untypeable.Fold is equivalent to an infinite state Moore machine, so a stack of composed transducers applied to a base Moore machine which produces whatever result you want can be compiled a really efficient form.
Early termination can be done by changing `merge` to `merge :: st -> i -> Either o st`.