diff --git a/byg/src/ComputationM.hs b/byg/src/ComputationM.hs index d718e01..6eaaa4a 100644 --- a/byg/src/ComputationM.hs +++ b/byg/src/ComputationM.hs @@ -2,6 +2,8 @@ module ComputationM ( ComputationM , Token + , tupleTokens + , zipTokens , evalComputationM , inject , mapComputationM @@ -30,10 +32,17 @@ deriving instance (Show a, Show b) => Show (TypedRun a b) data Token a where Token :: Int -> Token a TupleToken :: Token a -> Token b -> Token (a, b) + ZipToken :: Token [a] -> Token [b] -> Token [(a, b)] NoToken :: Token () deriving instance Show (Token a) +tupleTokens :: (Show a, Show b) => Token a -> Token b -> Token (a, b) +tupleTokens = TupleToken + +zipTokens :: (Show a, Show b) => Token [a] -> Token [b] -> Token [(a, b)] +zipTokens = ZipToken + data Dependency a b = Dependency (Token a) (TypedRun a b) (Token b) deriving (Show) diff --git a/byg/src/Functions.hs b/byg/src/Functions.hs index 9aec2f8..1cf19e2 100644 --- a/byg/src/Functions.hs +++ b/byg/src/Functions.hs @@ -3,7 +3,6 @@ module Functions ( isImageFilename , convertedImageFilename , listDirectory - , openImage , convertImage , saveFile , runPandoc @@ -17,7 +16,6 @@ isImageFilename = runFunction IsImageFilename convertedImageFilename = runFunction ConvertedImageFilename listDirectory = runFunctionIO ListDirectory -openImage = runFunctionIO OpenImage convertImage = runFunctionIO ConvertImage saveFile = runFunctionIO SaveFile runPandoc = runFunctionIO RunPandoc diff --git a/byg/src/Main.hs b/byg/src/Main.hs index 48f7f9a..c0cdf1e 100644 --- a/byg/src/Main.hs +++ b/byg/src/Main.hs @@ -1,5 +1,6 @@ module Main where +import Types import ComputationM import Functions @@ -7,16 +8,16 @@ handleRecipeDir :: Token FilePath -> ComputationM () handleRecipeDir dir = do dirContents <- listDirectory dir imageFilenames <- filterComputationM isImageFilename dirContents - t <- inject ("hej", "hey.txt") - saveFile t + convertedImageFilenames <- mapComputationM convertedImageFilename imageFilenames + flip mapComputationM_ (zipTokens imageFilenames convertedImageFilenames) $ \files -> do + settings <- inject $ ResizeToWidth 800 + convertImage $ tupleTokens files settings test :: ComputationM () test = do dir <- inject "retter" dirContents <- listDirectory dir mapComputationM_ handleRecipeDir dirContents - t <- inject ("hej", "hey.txt") - saveFile t main :: IO () main = mapM_ print $ evalComputationM test diff --git a/byg/src/Sources.hs b/byg/src/Sources.hs index b7fbd00..a38c13f 100644 --- a/byg/src/Sources.hs +++ b/byg/src/Sources.hs @@ -1,3 +1,4 @@ +{-# OPTIONS_GHC -Wno-orphans #-} module Sources where -- TODO: Figure out if any of this is useful. @@ -10,7 +11,7 @@ data Source a where instance SourceState FilePath where stateOfSource = undefined -instance SourceState Image where +instance SourceState ((FilePath, FilePath), ImageConversionSettings) where stateOfSource = undefined instance SourceState (String, FilePath) where diff --git a/byg/src/Types.hs b/byg/src/Types.hs index dfc5c44..6c4602a 100644 --- a/byg/src/Types.hs +++ b/byg/src/Types.hs @@ -3,7 +3,7 @@ module Types where import Data.ByteString (ByteString) -data Image = Image +data ImageConversionSettings = ResizeToWidth Int deriving (Show) class (SourceState a, Show f) => IsFunction f a b | f -> a b where