How should I avoid cyclic dependency between application state and asynchronous worker? #472
-
The custom event type is asynchronous worker's response. I want the response to contain the current state. If the current state contains form, it depends on the worker response type. Worker request and worker response now depend on application state. This creates circular dependency between worker and the part of application state that has form. If worker response doesn't contain the current state, I have to check whether the current application state matches the response. If the current state is not appropriate for the response, it is an error. This error checking adds a substantial amount of boilerplate. How should I cut the cyclic dependency? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 11 replies
-
It might be really helpful if you could provide at least a sketch of the concrete data types you're using. I'm having a hard time understanding your situation without more information, and it also isn't clear to me why these circular dependencies are problematic in your situation. (Mutually recursive types are common in Haskell, so that isn't inherently problematic.) |
Beta Was this translation helpful? Give feedback.
Oh, I see - you didn't mention module dependency in your original post. There are three approaches that come to mind for me:
.hs-boot
file to make the circular dependency compile. This is a good approach when the modules involved must not be combined for some reason, but I personally try to avoid boot files unless there's no better way.MyPkg.Types
, put the types in there, then importMyPkg.Types
in both of the modules that would have otherwise depended on each other.