From c588dc1f56edd7fb99d3bd855a10cbb202ec81b7 Mon Sep 17 00:00:00 2001 From: "Niels G. W. Serup" Date: Sat, 21 Sep 2024 19:17:09 +0200 Subject: [PATCH] User better namings --- byg/src/ComputationM.hs | 27 +++++++++++---------------- byg/src/Functions.hs | 18 +++++++++--------- byg/src/Main.hs | 2 +- 3 files changed, 21 insertions(+), 26 deletions(-) diff --git a/byg/src/ComputationM.hs b/byg/src/ComputationM.hs index 6068aa8..723f49a 100644 --- a/byg/src/ComputationM.hs +++ b/byg/src/ComputationM.hs @@ -8,18 +8,13 @@ import Unsafe.Coerce (unsafeCoerce) import Control.Monad.State import Control.Monad.Writer - - 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 + Function :: IsFunction f a b => f -> TypedRun a b + FunctionIO :: IsFunctionIO f a b => f -> TypedRun a b + Inject :: b -> TypedRun () b GetListElem :: TypedRun () b SetListElem :: TypedRun a () - InList :: [DependencyUntyped] -> TypedRun [a] [b] - -instance Show (ComputationM a) where - show _ = "" + MapComp :: [DependencyUntyped] -> TypedRun [a] [b] deriving instance (Show a, Show b) => Show (TypedRun a b) @@ -57,7 +52,7 @@ genDependency g = do pure target inject :: Show a => a -> ComputationM a -inject x = genDependency (Dependency NoToken (TInject x)) +inject x = genDependency (Dependency NoToken (Inject x)) getListElem :: Show a => ComputationM a getListElem = genDependency (Dependency NoToken GetListElem) @@ -65,14 +60,14 @@ getListElem = genDependency (Dependency NoToken GetListElem) setListElem :: Show a => Token a -> ComputationM () setListElem a = genDependency (Dependency a SetListElem) -run :: (Show a, Show b, IsF f a b) => f -> Token a -> ComputationM b -run f input = genDependency (Dependency input (F f)) +run :: (Show a, Show b, IsFunction f a b) => f -> Token a -> ComputationM b +run f input = genDependency (Dependency input (Function f)) isImageFilename = run IsImageFilename convertedImageFilename = run ConvertedImageFilename -runIO :: (Show a, Show b, IsFIO f a b) => f -> Token a -> ComputationM b -runIO f input = genDependency (Dependency input (FIO f)) +runIO :: (Show a, Show b, IsFunctionIO f a b) => f -> Token a -> ComputationM b +runIO f input = genDependency (Dependency input (FunctionIO f)) listDirectory = runIO ListDirectory openImage = runIO OpenImage @@ -80,8 +75,8 @@ convertImage = runIO ConvertImage saveFile = runIO SaveFile runPandoc = runIO RunPandoc -mapListTaken :: (Show a, Show b) => (Token a -> ComputationM b) -> Token [a] -> ComputationM [b] -mapListTaken f input = genDependency (Dependency input (InList (evalComputationM m))) +mapComputationM :: (Show a, Show b) => (Token a -> ComputationM b) -> Token [a] -> ComputationM [b] +mapComputationM f input = genDependency (Dependency input (MapComp (evalComputationM m))) where m :: ComputationM () m = do inp <- getListElem diff --git a/byg/src/Functions.hs b/byg/src/Functions.hs index 7393dde..cdeef36 100644 --- a/byg/src/Functions.hs +++ b/byg/src/Functions.hs @@ -5,37 +5,37 @@ module Functions where import Types import Sources -class (SourceState a, Show f) => IsF f a b | f -> a b where +class (SourceState a, Show f) => IsFunction f a b | f -> a b where runF :: f -> a -> b data IsImageFilename = IsImageFilename deriving (Show) -instance IsF IsImageFilename FilePath Bool where +instance IsFunction IsImageFilename FilePath Bool where runF IsImageFilename _path = undefined data ConvertedImageFilename = ConvertedImageFilename deriving (Show) -instance IsF ConvertedImageFilename FilePath FilePath where +instance IsFunction ConvertedImageFilename FilePath FilePath where runF ConvertedImageFilename _path = undefined -class (SourceState a, Show f) => IsFIO f a b | f -> a b where +class (SourceState a, Show f) => IsFunctionIO f a b | f -> a b where runFIO :: f -> a -> IO b data ListDirectory = ListDirectory deriving (Show) -instance IsFIO ListDirectory FilePath [FilePath] where +instance IsFunctionIO ListDirectory FilePath [FilePath] where runFIO ListDirectory _path = undefined data OpenImage = OpenImage deriving (Show) -instance IsFIO OpenImage FilePath Image where +instance IsFunctionIO OpenImage FilePath Image where runFIO OpenImage _path = undefined data ConvertImage = ConvertImage deriving (Show) -instance IsFIO ConvertImage Image Image where +instance IsFunctionIO ConvertImage Image Image where runFIO ConvertImage _image = undefined data SaveFile = SaveFile deriving (Show) -instance IsFIO SaveFile (String, FilePath) () where +instance IsFunctionIO SaveFile (String, FilePath) () where runFIO SaveFile _source = undefined data RunPandoc = RunPandoc deriving (Show) -instance IsFIO RunPandoc String String where +instance IsFunctionIO RunPandoc String String where runFIO RunPandoc _source = undefined diff --git a/byg/src/Main.hs b/byg/src/Main.hs index a137df8..10bd205 100644 --- a/byg/src/Main.hs +++ b/byg/src/Main.hs @@ -7,7 +7,7 @@ test :: ComputationM () test = do dir <- inject "retter" dirContents <- listDirectory dir - u <- mapListTaken openImage dirContents + u <- mapComputationM openImage dirContents pure $ NoToken main :: IO ()