Skip to content

Instantly share code, notes, and snippets.

@jferris
Created April 14, 2016 19:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jferris/5dd97405bba2900b3f3bf6c4ff4bd5b9 to your computer and use it in GitHub Desktop.
Save jferris/5dd97405bba2900b3f3bf6c4ff4bd5b9 to your computer and use it in GitHub Desktop.
Arrows
{-# 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