neohaskell / NeoHaskell

⏩ NeoHaskell is a dialect of Haskell that is focused on newcomer-friendliness and productivity.
https://neohaskell.org
Apache License 2.0
275 stars 3 forks source link

Nested Actions wont be executed #119

Closed NickSeagull closed 1 month ago

NickSeagull commented 1 month ago

Description

There is a bug in NeoHaskell's action system that prevents actions from being executed when used inside nested modules. This issue arises because of how actions are serialized and then deserialized using Data.Dynamic, which fails to properly match the event types of nested modules.

Details

NeoHaskell adopts a structure similar to the Elm architecture, but instead of calling commands "commands," NeoHaskell refers to them as "actions." For example, to read a file, you use the readText action, which publishes an object into a queue for asynchronous execution by an action worker. Importantly, the submission and execution of actions are entirely decoupled, leading to serialization of the action into an UnknownValue (Data.Dynamic).

Actions in NeoHaskell are polymorphic over a type variable representing the event type, similar to Elm's message type system. The main process is as follows:

  1. Event Registration: At the beginning of the application, action handlers are registered for the main event type of the user application. For example, the readTextHandler is registered for the main event type.

  2. Issue with Nested Modules: When attempting to execute actions within nested modules, actions are not executed because the Data.Dynamic type casting process expects the top-level event type of the user application rather than the nested module's event type. This mismatch causes the action handler to fail, and thus, actions in nested modules are not executed.

Problem Scenario

If a user tries to perform an action, such as reading a file inside a nested module, the action will not execute because the action handler is looking for the top-level event type instead of the nested module's event type.

Proposed Solution

To address this issue, we need to modify NeoHaskell's initialization process to ensure that nested modules are treated as part of the user application. Specifically, we should:

Action Items

  1. Update the initialization process to include nested modules as part of the user application.
  2. Ensure that action handlers can be registered multiple times for different event types corresponding to nested modules.
  3. Validate that actions in nested modules execute correctly without type casting errors.
NickSeagull commented 1 month ago

Fixed in #123