<commit_before>{-# LANGUAGE RecordWildCards, RecursiveDo #-}
module Reactive.Threepenny.PulseLatch (
    Pulse, newPulse, addHandler,
    neverP, mapP, filterJustP, unionWithP, unsafeMapIOP,
    
    Latch,
    pureL, mapL, applyL, accumL, applyP,
    readLatch,
    ) where


import Control.Applicative
import Control.Monad
import Control.Monad.Trans.Class
import Control.Monad.Trans.RWS     as Monad

import Data.Hashable
import Data.IORef
import Data.Monoid (Endo(..))

import Data.Unique.Really
import qualified Data.Vault.Lazy   as Vault
import qualified Data.HashMap.Lazy as Map

type Vault = Vault.Vault
type Map   = Map.HashMap


type Build = IO

{-----------------------------------------------------------------------------
    Pulse
------------------------------------------------------------------------------}
type EvalP = Monad.RWST () () Vault IO

runEvalP :: Vault -> EvalP a -> IO (a, Vault)
runEvalP pulses m = do
    (a, s, w) <- Monad.runRWST m () pulses
    return (a, s)


type Handler  = EvalP (IO ())
data Priority = DoLatch | DoIO deriving (Eq,Show,Ord,Enum)

instance Hashable Priority where hash = fromEnum

data Pulse a = Pulse
    { addHandlerP :: ((Unique, Priority), Handler) -> Build ()
    , evalP       :: EvalP (Maybe a)
    }

-- Turn evaluation action into pulse that caches the value.
cacheEval :: EvalP (Maybe a) -> Build (Pulse a)
cacheEval e = do
    key <- Vault.newKey
    return $ Pulse<commit_msg>Adjusting a 'Hashable' instance for compatibility with 'hashable-1.2.*'.<commit_after>{-# LANGUAGE RecordWildCards, RecursiveDo #-}
module Reactive.Threepenny.PulseLatch (
    Pulse, newPulse, addHandler,
    neverP, mapP, filterJustP, unionWithP, unsafeMapIOP,
    
    Latch,
    pureL, mapL, applyL, accumL, applyP,
    readLatch,
    ) where


import Control.Applicative
import Control.Monad
import Control.Monad.Trans.Class
import Control.Monad.Trans.RWS     as Monad

import Data.Hashable
import Data.IORef
import Data.Monoid (Endo(..))

import Data.Unique.Really
import qualified Data.Vault.Lazy   as Vault
import qualified Data.HashMap.Lazy as Map

type Vault = Vault.Vault
type Map   = Map.HashMap


type Build = IO

{-----------------------------------------------------------------------------
    Pulse
------------------------------------------------------------------------------}
type EvalP = Monad.RWST () () Vault IO

runEvalP :: Vault -> EvalP a -> IO (a, Vault)
runEvalP pulses m = do
    (a, s, w) <- Monad.runRWST m () pulses
    return (a, s)


type Handler  = EvalP (IO ())
data Priority = DoLatch | DoIO deriving (Eq,Show,Ord,Enum)

instance Hashable Priority where hashWithSalt _ = fromEnum

data Pulse a = Pulse
    { addHandlerP :: ((Unique, Priority), Handler) -> Build ()
    , evalP       :: EvalP (Maybe a)
    }

-- Turn evaluation action into pulse that caches the value.
cacheEval :: EvalP (Maybe a) -> Build (Pulse a)
cacheEval e = do
    key <- Vault.newKey
    return $ Pulse
{'fraction_non_alphanumeric': 0.2, 'fraction_numerical': 0.0006768189509306261, 'mean_word_length': 2.202600216684724, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, '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': '1066367', 'n_tokens_mistral': 952, 'n_tokens_neox': 920, 'n_words': 282}