-
-
Save SkyWriter/6123d23a2c3f0d734224ea67ff010be7 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