From f12ac12ea8d9cca48eca064c3aefc30c4333bc59 Mon Sep 17 00:00:00 2001 From: "Niels G. W. Serup" Date: Sat, 21 Sep 2024 18:45:39 +0200 Subject: [PATCH] Remove mapM usage in monad Was really a hack. --- byg/src/ComputationM.hs | 4 ++++ byg/src/Main.hs | 9 +++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/byg/src/ComputationM.hs b/byg/src/ComputationM.hs index 8f54603..fa222a9 100644 --- a/byg/src/ComputationM.hs +++ b/byg/src/ComputationM.hs @@ -15,6 +15,7 @@ data TypedRun a b where F :: IsF f a b => f -> TypedRun a b FIO :: IsFIO f a b => f -> TypedRun a b TInject :: b -> TypedRun () b + GetListElem :: TypedRun () b InList :: ComputationM TokenNotTraversable b -> TypedRun [a] [b] instance Show (ComputationM t a) where @@ -69,6 +70,9 @@ genDependency g = do inject :: Show a => a -> ComputationM ta a inject x = genDependency (Dependency NoToken (TInject x)) +getListElem :: Show a => ComputationM ta a +getListElem = genDependency (Dependency NoToken GetListElem) + run :: (Show a, Show b, IsF f a b) => f -> Token t a -> ComputationM TokenNotTraversable b run f input = genDependency (Dependency input (F f)) diff --git a/byg/src/Main.hs b/byg/src/Main.hs index 90dc4bc..cee6fa3 100644 --- a/byg/src/Main.hs +++ b/byg/src/Main.hs @@ -1,13 +1,18 @@ module Main where +import Types import ComputationM +testSub :: ComputationM TokenNotTraversable Image +testSub = do + inp <- getListElem + openImage inp + test :: ComputationM TokenNotTraversable () test = do dir <- inject "retter" dirContents <- listDirectory dir - let dirContents' = makeTraversable dirContents - u <- mapM openImage dirContents' + u <- mapListTaken testSub dirContents pure $ NoToken main :: IO ()