Skip to content

Instantly share code, notes, and snippets.

View cutsea110's full-sized avatar

cutsea110 cutsea110

View GitHub Profile
@WillNess
WillNess / foldr-insert.hs
Last active October 22, 2017 04:41
foldr - insert - paramorphism
http://stackoverflow.com/questions/20568276/implement-insert-in-haskell-with-foldr
/20570385#20570385
----
You need a [paramorphism](http://stackoverflow.com/a/13317563/849891) for that:
para :: (a -> [a] -> b -> b) -> b -> [a] -> b
foldr :: (a -> b -> b) -> b -> [a] -> b
para c n (x : xs) = c x xs (para c n xs)