Last active
December 18, 2017 18:22
-
-
Save sawaken/b802151e60423a1b344e to your computer and use it in GitHub Desktop.
Hello World of Yampa, Haskell's FRP library.
This file contains hidden or 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 Arrows #-} | |
import qualified FRP.Yampa as Y | |
type Inp = (String, String) | |
type Out = String | |
main = do | |
rh <- Y.reactInit initIO act sf | |
loop rh | |
loop :: Y.ReactHandle Inp Out -> IO () | |
loop rh = do | |
i <- initIO | |
flag <- Y.react rh (1, Just i) | |
loop rh | |
initIO :: IO Inp | |
initIO = do | |
cont1 <- readFile "./file1.txt" | |
cont2 <- readFile "./file2.txt" | |
return (cont1, cont2) | |
act :: Y.ReactHandle Inp Out -> Bool -> Out -> IO Bool | |
act rh ch out = do | |
putStrLn ("out:" ++ show out) | |
putStrLn "--------------------" | |
return False | |
sf :: Y.SF Inp Out | |
sf = proc i -> do | |
out <- Y.arr (\(s1, s2) -> chomp s1 ++ chomp s2) -< i | |
t <- Y.time -< () | |
Y.returnA -< out ++ "--" ++ show t | |
chomp :: String -> String | |
chomp = filter (\c -> c /= '\n') |
This file contains hidden or 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 Arrows #-} | |
import FRP.Yampa | |
main = reactimate initial input actuation sf | |
initial :: IO (String, String) | |
initial = do cont1 <- readFile "./file1.txt" | |
cont2 <- readFile "./file2.txt" | |
return (cont1, cont2) | |
input :: Bool -> IO (DTime, Maybe (String, String)) | |
input bl = do i <- initial | |
return (1, Just i) | |
actuation :: Bool -> String -> IO Bool | |
actuation ch out = do putStrLn out | |
return False | |
sf :: SF (String, String) String | |
sf = proc i -> do | |
out <- arr (\(s1, s2) -> chomp s1 ++ chomp s2) -< i | |
t <- time -< () | |
returnA -< out ++ "--" ++ show t | |
chomp :: String -> String | |
chomp = filter (\c -> c /= '\n') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment