How do I convert the following unacceptable (“unsupported cyclic reference between types/traits detected”) Rust to something that works?
type Generator<A> = Fn(Consumer<A>) -> bool;
type Consumer<A> = Fn(A, bool, Generator<A>) -> bool;
I want to define closures of these generator and consumer types.
I’m trying to translate this from Haskell but am not sure how to. Here’s the Haskell, where circularity is broken through newtype
. I realize that there are constraints in Rust because of the nature of closures as actually different-sized structs with explicit environment captures synthesized by the compiler to implement the function traits, but breaking the circularity is stumping me somehow.
newtype Generator a = G { runG :: Consumer a -> Bool }
newtype Consumer a = C { runC :: a -> Bool -> Generator a -> Bool }