Skip to content

Commit

Permalink
feat: impl Applicative for Task
Browse files Browse the repository at this point in the history
  • Loading branch information
matthunz committed Jan 30, 2025
1 parent bc093e9 commit 1fce47f
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/Data/Aztecs/System.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE MultiParamTypeClasses #-}
Expand Down Expand Up @@ -37,6 +38,21 @@ newtype Task m i o = Task
i -> Components -> m (o, World -> World, Access m ())
)
}
deriving (Functor)

instance (Monad m) => Applicative (Task m i) where
pure a = Task (,[],\_ _ -> pure (a, id, pure ()))
f <*> a =
Task $ \w ->
let (w', cIds, f') = runTask f w
(w'', cIds', a') = runTask a w'
in ( w'',
cIds <> cIds',
\i cs -> do
(f'', fG, access) <- f' i cs
(a'', aG, access') <- a' i cs
return (f'' a'', fG . aG, access >> access')
)

(<&>) :: (Monad m) => Task m i o -> Task m o a -> Task m i a
t1 <&> t2 =
Expand Down

0 comments on commit 1fce47f

Please sign in to comment.