Skip to content

Instantly share code, notes, and snippets.

@kseo
Created January 27, 2016 02:40
Show Gist options
  • Select an option

  • Save kseo/c709a26798071821cae5 to your computer and use it in GitHub Desktop.

Select an option

Save kseo/c709a26798071821cae5 to your computer and use it in GitHub Desktop.
Reduce
class Reduce t where
reducer :: (a -> b -> b) -> (t a -> b -> b)
reducel :: (b -> a -> b) -> (b -> t a -> b)
instance Reduce [] where
reducer f x z = foldr f z x
reducel f x z = foldl f x z
toList :: (Reduce f) => f a -> [a]
toList s = s `cons` [] where cons = reducer (:)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment