User better namings
This commit is contained in:
parent
d0c2b47df0
commit
c588dc1f56
|
@ -8,18 +8,13 @@ import Unsafe.Coerce (unsafeCoerce)
|
||||||
import Control.Monad.State
|
import Control.Monad.State
|
||||||
import Control.Monad.Writer
|
import Control.Monad.Writer
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
data TypedRun a b where
|
data TypedRun a b where
|
||||||
F :: IsF f a b => f -> TypedRun a b
|
Function :: IsFunction f a b => f -> TypedRun a b
|
||||||
FIO :: IsFIO f a b => f -> TypedRun a b
|
FunctionIO :: IsFunctionIO f a b => f -> TypedRun a b
|
||||||
TInject :: b -> TypedRun () b
|
Inject :: b -> TypedRun () b
|
||||||
GetListElem :: TypedRun () b
|
GetListElem :: TypedRun () b
|
||||||
SetListElem :: TypedRun a ()
|
SetListElem :: TypedRun a ()
|
||||||
InList :: [DependencyUntyped] -> TypedRun [a] [b]
|
MapComp :: [DependencyUntyped] -> TypedRun [a] [b]
|
||||||
|
|
||||||
instance Show (ComputationM a) where
|
|
||||||
show _ = "<computation>"
|
|
||||||
|
|
||||||
deriving instance (Show a, Show b) => Show (TypedRun a b)
|
deriving instance (Show a, Show b) => Show (TypedRun a b)
|
||||||
|
|
||||||
|
@ -57,7 +52,7 @@ genDependency g = do
|
||||||
pure target
|
pure target
|
||||||
|
|
||||||
inject :: Show a => a -> ComputationM a
|
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 :: Show a => ComputationM a
|
||||||
getListElem = genDependency (Dependency NoToken GetListElem)
|
getListElem = genDependency (Dependency NoToken GetListElem)
|
||||||
|
@ -65,14 +60,14 @@ getListElem = genDependency (Dependency NoToken GetListElem)
|
||||||
setListElem :: Show a => Token a -> ComputationM ()
|
setListElem :: Show a => Token a -> ComputationM ()
|
||||||
setListElem a = genDependency (Dependency a SetListElem)
|
setListElem a = genDependency (Dependency a SetListElem)
|
||||||
|
|
||||||
run :: (Show a, Show b, IsF f a b) => f -> Token a -> ComputationM b
|
run :: (Show a, Show b, IsFunction f a b) => f -> Token a -> ComputationM b
|
||||||
run f input = genDependency (Dependency input (F f))
|
run f input = genDependency (Dependency input (Function f))
|
||||||
|
|
||||||
isImageFilename = run IsImageFilename
|
isImageFilename = run IsImageFilename
|
||||||
convertedImageFilename = run ConvertedImageFilename
|
convertedImageFilename = run ConvertedImageFilename
|
||||||
|
|
||||||
runIO :: (Show a, Show b, IsFIO f a b) => f -> Token a -> ComputationM b
|
runIO :: (Show a, Show b, IsFunctionIO f a b) => f -> Token a -> ComputationM b
|
||||||
runIO f input = genDependency (Dependency input (FIO f))
|
runIO f input = genDependency (Dependency input (FunctionIO f))
|
||||||
|
|
||||||
listDirectory = runIO ListDirectory
|
listDirectory = runIO ListDirectory
|
||||||
openImage = runIO OpenImage
|
openImage = runIO OpenImage
|
||||||
|
@ -80,8 +75,8 @@ convertImage = runIO ConvertImage
|
||||||
saveFile = runIO SaveFile
|
saveFile = runIO SaveFile
|
||||||
runPandoc = runIO RunPandoc
|
runPandoc = runIO RunPandoc
|
||||||
|
|
||||||
mapListTaken :: (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]
|
||||||
mapListTaken f input = genDependency (Dependency input (InList (evalComputationM m)))
|
mapComputationM f input = genDependency (Dependency input (MapComp (evalComputationM m)))
|
||||||
where m :: ComputationM ()
|
where m :: ComputationM ()
|
||||||
m = do
|
m = do
|
||||||
inp <- getListElem
|
inp <- getListElem
|
||||||
|
|
|
@ -5,37 +5,37 @@ module Functions where
|
||||||
import Types
|
import Types
|
||||||
import Sources
|
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
|
runF :: f -> a -> b
|
||||||
|
|
||||||
data IsImageFilename = IsImageFilename deriving (Show)
|
data IsImageFilename = IsImageFilename deriving (Show)
|
||||||
instance IsF IsImageFilename FilePath Bool where
|
instance IsFunction IsImageFilename FilePath Bool where
|
||||||
runF IsImageFilename _path = undefined
|
runF IsImageFilename _path = undefined
|
||||||
|
|
||||||
data ConvertedImageFilename = ConvertedImageFilename deriving (Show)
|
data ConvertedImageFilename = ConvertedImageFilename deriving (Show)
|
||||||
instance IsF ConvertedImageFilename FilePath FilePath where
|
instance IsFunction ConvertedImageFilename FilePath FilePath where
|
||||||
runF ConvertedImageFilename _path = undefined
|
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
|
runFIO :: f -> a -> IO b
|
||||||
|
|
||||||
data ListDirectory = ListDirectory deriving (Show)
|
data ListDirectory = ListDirectory deriving (Show)
|
||||||
instance IsFIO ListDirectory FilePath [FilePath] where
|
instance IsFunctionIO ListDirectory FilePath [FilePath] where
|
||||||
runFIO ListDirectory _path = undefined
|
runFIO ListDirectory _path = undefined
|
||||||
|
|
||||||
data OpenImage = OpenImage deriving (Show)
|
data OpenImage = OpenImage deriving (Show)
|
||||||
instance IsFIO OpenImage FilePath Image where
|
instance IsFunctionIO OpenImage FilePath Image where
|
||||||
runFIO OpenImage _path = undefined
|
runFIO OpenImage _path = undefined
|
||||||
|
|
||||||
data ConvertImage = ConvertImage deriving (Show)
|
data ConvertImage = ConvertImage deriving (Show)
|
||||||
instance IsFIO ConvertImage Image Image where
|
instance IsFunctionIO ConvertImage Image Image where
|
||||||
runFIO ConvertImage _image = undefined
|
runFIO ConvertImage _image = undefined
|
||||||
|
|
||||||
data SaveFile = SaveFile deriving (Show)
|
data SaveFile = SaveFile deriving (Show)
|
||||||
instance IsFIO SaveFile (String, FilePath) () where
|
instance IsFunctionIO SaveFile (String, FilePath) () where
|
||||||
runFIO SaveFile _source = undefined
|
runFIO SaveFile _source = undefined
|
||||||
|
|
||||||
data RunPandoc = RunPandoc deriving (Show)
|
data RunPandoc = RunPandoc deriving (Show)
|
||||||
instance IsFIO RunPandoc String String where
|
instance IsFunctionIO RunPandoc String String where
|
||||||
runFIO RunPandoc _source = undefined
|
runFIO RunPandoc _source = undefined
|
||||||
|
|
|
@ -7,7 +7,7 @@ test :: ComputationM ()
|
||||||
test = do
|
test = do
|
||||||
dir <- inject "retter"
|
dir <- inject "retter"
|
||||||
dirContents <- listDirectory dir
|
dirContents <- listDirectory dir
|
||||||
u <- mapListTaken openImage dirContents
|
u <- mapComputationM openImage dirContents
|
||||||
pure $ NoToken
|
pure $ NoToken
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
|
|
Loading…
Reference in New Issue