Skip to content

Instantly share code, notes, and snippets.

@joker1007
Created June 30, 2012 13:42
Show Gist options
  • Save joker1007/3023787 to your computer and use it in GitHub Desktop.
Save joker1007/3023787 to your computer and use it in GitHub Desktop.
{-# LANGUAGE Arrows #-}
import Control.Arrow
multiply2 :: (Num a) => (->) a a
multiply2 = arr (\x -> x * 2)
multiply4 :: (Num a) => (->) a a
multiply4 = arr (\x -> x * 4)
addA f g = proc x -> do
y <- f -< x
z <- g -< x
returnA -< (y + z)
plus1 :: Int -> Int
plus1 = proc x -> returnA -< (x + 1)
plus3 :: Int -> Int
plus3 = proc x -> returnA -< (x + 3)
plus2 :: Int -> Int
plus2 = proc y -> do x <- plus1 -< y
plus1 -< x
comparr :: Int -> Int
comparr = plus1 >>> plus3 >>> plus2
main :: IO()
main = putStrLn $ show $ addA multiply2 multiply4 (5.5 :: Float)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment