Created
April 14, 2016 19:46
-
-
Save jferris/5dd97405bba2900b3f3bf6c4ff4bd5b9 to your computer and use it in GitHub Desktop.
Arrows
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 Arrows #-} | |
import Control.Arrow | |
double :: Int -> Int | |
double x = x * 2 | |
triple :: Int -> Int | |
triple x = x * 3 | |
increment :: Int -> Int | |
increment x = x + 1 | |
combine :: Int -> Int | |
combine = | |
( double &&& increment | |
>>^ (\(x, y) -> x + y) | |
) &&& triple >>^ (\(x, y) -> x + y) | |
combine' :: Int -> Int | |
combine' = proc x -> do | |
a <- double -< x | |
b <- increment -< x | |
c <- triple -< x | |
returnA -< a + b + c |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment