Put function shortcuts back in Functions module
This commit is contained in:
parent
e3868332be
commit
28d430cf72
|
@ -1,10 +1,15 @@
|
||||||
module ComputationM where
|
module ComputationM
|
||||||
|
( ComputationM
|
||||||
|
, evalComputationM
|
||||||
|
, inject
|
||||||
|
, mapComputationM
|
||||||
|
, runFunction
|
||||||
|
, runFunctionIO
|
||||||
|
) where
|
||||||
|
|
||||||
import Types
|
import Types
|
||||||
import Sources
|
import Sources
|
||||||
import Functions
|
|
||||||
|
|
||||||
import Unsafe.Coerce (unsafeCoerce)
|
|
||||||
import Control.Monad.State
|
import Control.Monad.State
|
||||||
import Control.Monad.Writer
|
import Control.Monad.Writer
|
||||||
|
|
||||||
|
@ -71,20 +76,11 @@ setListElem a outer = do
|
||||||
tellDep (Dependency a SetListElem outer)
|
tellDep (Dependency a SetListElem outer)
|
||||||
pure NoToken
|
pure NoToken
|
||||||
|
|
||||||
run :: (Show a, Show b, IsFunction f a b) => f -> Token a -> ComputationM b
|
runFunction :: (Show a, Show b, IsFunction f a b) => f -> Token a -> ComputationM b
|
||||||
run f input = genDependency (Dependency input (Function f))
|
runFunction f input = genDependency (Dependency input (Function f))
|
||||||
|
|
||||||
isImageFilename = run IsImageFilename
|
runFunctionIO :: (Show a, Show b, IsFunctionIO f a b) => f -> Token a -> ComputationM b
|
||||||
convertedImageFilename = run ConvertedImageFilename
|
runFunctionIO f input = genDependency (Dependency input (FunctionIO 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
|
|
||||||
convertImage = runIO ConvertImage
|
|
||||||
saveFile = runIO SaveFile
|
|
||||||
runPandoc = runIO RunPandoc
|
|
||||||
|
|
||||||
mapComputationM :: (Show a, Show b) => (Token a -> ComputationM b) -> Token [a] -> ComputationM [b]
|
mapComputationM :: (Show a, Show b) => (Token a -> ComputationM b) -> Token [a] -> ComputationM [b]
|
||||||
mapComputationM f input = genDependency' $ \target -> do
|
mapComputationM f input = genDependency' $ \target -> do
|
||||||
|
|
|
@ -1,7 +1,16 @@
|
||||||
module Functions where
|
{-# OPTIONS_GHC -Wno-missing-signatures #-}
|
||||||
|
module Functions
|
||||||
|
( isImageFilename
|
||||||
|
, convertedImageFilename
|
||||||
|
, listDirectory
|
||||||
|
, openImage
|
||||||
|
, convertImage
|
||||||
|
, saveFile
|
||||||
|
, runPandoc
|
||||||
|
) where
|
||||||
|
|
||||||
import Types
|
import Types
|
||||||
import Sources
|
import ComputationM
|
||||||
|
|
||||||
data IsImageFilename = IsImageFilename deriving (Show)
|
data IsImageFilename = IsImageFilename deriving (Show)
|
||||||
instance IsFunction IsImageFilename FilePath Bool where
|
instance IsFunction IsImageFilename FilePath Bool where
|
||||||
|
@ -31,3 +40,13 @@ instance IsFunctionIO SaveFile (String, FilePath) () where
|
||||||
data RunPandoc = RunPandoc deriving (Show)
|
data RunPandoc = RunPandoc deriving (Show)
|
||||||
instance IsFunctionIO RunPandoc String String where
|
instance IsFunctionIO RunPandoc String String where
|
||||||
runFIO RunPandoc _source = undefined
|
runFIO RunPandoc _source = undefined
|
||||||
|
|
||||||
|
|
||||||
|
isImageFilename = runFunction IsImageFilename
|
||||||
|
convertedImageFilename = runFunction ConvertedImageFilename
|
||||||
|
|
||||||
|
listDirectory = runFunctionIO ListDirectory
|
||||||
|
openImage = runFunctionIO OpenImage
|
||||||
|
convertImage = runFunctionIO ConvertImage
|
||||||
|
saveFile = runFunctionIO SaveFile
|
||||||
|
runPandoc = runFunctionIO RunPandoc
|
||||||
|
|
|
@ -2,13 +2,15 @@ module Main where
|
||||||
|
|
||||||
import Types
|
import Types
|
||||||
import ComputationM
|
import ComputationM
|
||||||
|
import Functions
|
||||||
|
|
||||||
test :: ComputationM ()
|
test :: ComputationM ()
|
||||||
test = do
|
test = do
|
||||||
dir <- inject "retter"
|
dir <- inject "retter"
|
||||||
dirContents <- listDirectory dir
|
dirContents <- listDirectory dir
|
||||||
u <- mapComputationM openImage dirContents
|
u <- mapComputationM openImage dirContents
|
||||||
pure $ NoToken
|
t <- inject ("hej", "hey.txt")
|
||||||
|
saveFile t
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = mapM_ print $ evalComputationM test
|
main = mapM_ print $ evalComputationM test
|
||||||
|
|
Loading…
Reference in New Issue