diff --git a/byg/src/ComputationM.hs b/byg/src/ComputationM.hs index c2deafc..8f54603 100644 --- a/byg/src/ComputationM.hs +++ b/byg/src/ComputationM.hs @@ -12,7 +12,7 @@ import Control.Monad.Writer data TypedRun a b where - F :: Function a b -> TypedRun a b + F :: IsF f a b => f -> TypedRun a b FIO :: IsFIO f a b => f -> TypedRun a b TInject :: b -> TypedRun () b InList :: ComputationM TokenNotTraversable b -> TypedRun [a] [b] @@ -69,6 +69,12 @@ genDependency g = do inject :: Show a => a -> ComputationM ta a inject x = genDependency (Dependency NoToken (TInject x)) +run :: (Show a, Show b, IsF f a b) => f -> Token t a -> ComputationM TokenNotTraversable b +run f input = genDependency (Dependency input (F f)) + +isImageFilename = run IsImageFilename +convertedImageFilename = run ConvertedImageFilename + runIO :: (Show a, Show b, IsFIO f a b) => f -> Token t a -> ComputationM TokenNotTraversable b runIO f input = genDependency (Dependency input (FIO f)) @@ -78,7 +84,6 @@ convertImage = runIO ConvertImage saveFile = runIO SaveFile runPandoc = runIO RunPandoc - makeTraversable :: Token TokenNotTraversable [a] -> Token TokenTraversable (Token TokenNotTraversable a) makeTraversable (Token n) = Token n diff --git a/byg/src/Functions.hs b/byg/src/Functions.hs index 0ca37a8..7393dde 100644 --- a/byg/src/Functions.hs +++ b/byg/src/Functions.hs @@ -5,11 +5,17 @@ module Functions where import Types import Sources -data Function a b where - IsImageFilename :: Function FilePath Bool - ConvertedImageFilename :: Function FilePath FilePath +class (SourceState a, Show f) => IsF f a b | f -> a b where + runF :: f -> a -> b + +data IsImageFilename = IsImageFilename deriving (Show) +instance IsF IsImageFilename FilePath Bool where + runF IsImageFilename _path = undefined + +data ConvertedImageFilename = ConvertedImageFilename deriving (Show) +instance IsF ConvertedImageFilename FilePath FilePath where + runF ConvertedImageFilename _path = undefined -deriving instance Show (Function a b) class (SourceState a, Show f) => IsFIO f a b | f -> a b where runFIO :: f -> a -> IO b