constraints-emerge

Defer instance lookups until runtime https://github.com/isovector/constraints-emerge

Latest on Hackage:0.1.2

This package is not currently in any snapshots. If you're interested in using it, we recommend adding it to Stackage Nightly. Doing so will make builds more reliable, and allow stackage.org to host generated Haddocks.

MIT licensed by Sandy Maguire
Maintained by sandy@sandymaguire.me

This plugin allows you to write

{-# OPTIONS_GHC -fplugin Data.Constraint.Emerge.Plugin #-}
module Test where

import Data.Constraint.Emerge

showAnything :: forall c. Emerge (Show c) => c -> String
showAnything c =
case emerge @(Show c) of
Just Dict -> show c
Nothing   -> "{{unshowable}}"

where the 'Emerge (Show c)' will automatically be discharged for any monomorphic c.

See test/EmergeSpec.hs for a few examples of what this plugin can do for you.