Created
February 15, 2018 10:58
-
-
Save np/3e9fae5f9c89f3959713d0bd77b30d41 to your computer and use it in GitHub Desktop.
A pipeline example using MonadJob
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE GeneralizedNewtypeDeriving #-} | |
import Data.Aeson | |
type URL = String | |
newtype JobServerURL i o = JobServerURL URL | |
class Monad m => MonadJob m where | |
callJob :: (ToJSON i, FromJSON o) => JobServerURL i o -> i -> m o | |
newtype InputA = C1 () deriving (Eq, Show, ToJSON, FromJSON) | |
newtype OutputA = C2 () deriving (Eq, Show, ToJSON, FromJSON) | |
newtype InputB = C3 () deriving (Eq, Show, ToJSON, FromJSON) | |
newtype OutputB = C4 () deriving (Eq, Show, ToJSON, FromJSON) | |
newtype InputC = C5 () deriving (Eq, Show, ToJSON, FromJSON) | |
newtype OutputC = C6 () deriving (Eq, Show, ToJSON, FromJSON) | |
newtype Input = C7 () deriving (Eq, Show, ToJSON, FromJSON) | |
newtype Output = C8 () deriving (Eq, Show, ToJSON, FromJSON) | |
f1 :: Input -> InputA | |
f2 :: Input -> OutputA -> InputB | |
f3 :: Input -> OutputA -> OutputB -> InputC | |
f4 :: Input -> OutputA -> OutputB -> OutputC -> Output | |
(f1, f2, f3, f4) = undefined | |
serverA :: JobServerURL InputA OutputA | |
serverA = JobServerURL "http://hostA/taskA" | |
serverB :: JobServerURL InputB OutputB | |
serverB = JobServerURL "http://hostB/taskB" | |
serverC :: JobServerURL InputC OutputC | |
serverC = JobServerURL "http://hostC/taskC" | |
f :: MonadJob m => Input -> m Output | |
f data1 = do | |
data2 <- callJob serverA (f1 data1) | |
data3 <- callJob serverB (f2 data1 data2) | |
data4 <- callJob serverC (f3 data1 data2 data3) | |
return $ f4 data1 data2 data3 data4 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment