Skip to content

Instantly share code, notes, and snippets.

@oisdk
Created March 19, 2018 15:42
Show Gist options
  • Save oisdk/c42dc46c655d8ab87c10c235b1991cc3 to your computer and use it in GitHub Desktop.
Save oisdk/c42dc46c655d8ab87c10c235b1991cc3 to your computer and use it in GitHub Desktop.
newtype Free c a = Free { runFree ∷ ∀ b. c b ⇒ (a → b) → b }
type (a ∷ k → Constraint) ⊨ (b ∷ k → Constraint) = (∀ x. a x ⇒ b x ∷ Constraint)
instance (Monoid ⊨ c) ⇒ Foldable (Free c) where
foldMap = flip runFree
ala ∷ (∀ x. c x ⇒ c (f x), ∀ x. Coercible x (f x)) ⇒ Free c a → (∀ x. x → f x) → Free c a
ala xs to = Free (\k → coerce (runFree xs (to #. k)))
reverse ∷ Free Monoid a → Free Monoid a
reverse xs = xs `ala` Dual
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment