Skip to content

Instantly share code, notes, and snippets.

@aycanirican
Created August 8, 2010 22:12
Show Gist options
  • Save aycanirican/514620 to your computer and use it in GitHub Desktop.
Save aycanirican/514620 to your computer and use it in GitHub Desktop.
module Fold where
import Test.QuickCheck
op xs = go xs True 0 where
go [] _ acc = acc
go xs@(a:res) True acc = go res False (acc + a)
go xs@(a:res) False acc = go res True (acc - a)
prop_iso xs = foldr (-) 0 xs ≡ op xs
@evrim
Copy link

evrim commented Aug 8, 2010

*Fold.Test> foldl (flip (-)) 1 $ reverse [2..3]
0
*Fold.Test> foldr (-) 1 [2..3]
0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment