Skip to content

Instantly share code, notes, and snippets.

@ramirez7
Created June 14, 2024 15:46
Show Gist options
  • Save ramirez7/3b52ac4920eaf090ed646c189f19ea09 to your computer and use it in GitHub Desktop.
Save ramirez7/3b52ac4920eaf090ed646c189f19ea09 to your computer and use it in GitHub Desktop.
{-# LANGUAGE AllowAmbiguousTypes #-}
import Data.Coerce
import Data.Foldable
foldMapVia
:: forall b f r a
. Coercible r b
=> Monoid b
=> Foldable f
=> (a -> r)
-> f a
-> r
foldMapVia f = coerce @b @r . foldMap (coerce @r @b . f)
foldVia
:: forall b f r
. Coercible r b
=> Monoid b
=> Foldable f
=> f r
-> r
foldVia = foldMapVia @b id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment