<commit_before>{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ExistentialQuantification #-}
module Effect.Actor where

import Mop
import Mop.IO
import Effect.Exception
import Effect.Weave

import Control.Concurrent
import Control.Monad

import Data.Dynamic
import Data.IORef

import Unsafe.Coerce

import Data.Binary

type Name = String

data Message = Local ActorRef Dynamic

data ActorRef
  -- Message inbox wrapped in IORef to ease garbage collection when an actor is restarted.
  = ActorRef { actorRef :: (Name,IORef (MVar Message)) }

data ActorRec = ActorRec
  { name :: Name
  , inbox :: IORef (MVar Message)<commit_msg>Added some requirements for implementation.<commit_after>{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ExistentialQuantification #-}
module Effect.Actor where

import Mop
import Mop.IO
import Effect.Exception
import Effect.Weave

import Control.Concurrent
import Control.Monad

import Data.Dynamic
import Data.IORef

import Unsafe.Coerce

import Data.Binary

{-
Extract Promise API and use it both here and in all other concurrency frameworks
so they may interact (Actors/Agents/Fork).

Universe is a set of ActorRecs in an IORef for uniform access.

ActorRecs contain Name, Inbox, Parent ActorRef, Child ActorRefs, and termination
status wrapped in IORef for uniform access.

Inboxes are `MVar Message` wrapped in IORef for uniform access and GC guarantees.

Messages are passed with ActorRefs

Supervisors supervise uniformly.

Send can be asynchronous or synchronous.

System-level actor and supervisor exceptions induce actor system failure.

Supervision strategies should allow restarting (obj -> (e -> plan) -> plan),
resumption, and exception passing.

Might need a communication channel for exceptions passed to supervisor?
How do we handle this? Can we just use the rewrite strategy above to handle
the expected effects?
-}

type Name = String

data Message = Local ActorRef Dynamic

data ActorRef
  -- Message inbox wrapped in IORef to ease garbage collection when an actor is restarted.
  = ActorRef { actorRef :: (Name,IORef (MVar Message)) }

data ActorRec = ActorRec
  { name :: Name
  , inbox :: IORef (MVar Message)
{'fraction_non_alphanumeric': 0.0673903211216644, 'fraction_numerical': 0.0, 'mean_word_length': 4.502487562189055, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5789496', 'n_tokens_mistral': 667, 'n_tokens_neox': 628, 'n_words': 264}