Skip to content

Instantly share code, notes, and snippets.

@berdario
Last active June 26, 2016 19:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save berdario/2bf439e3ac9ba2ecd3f8031a1a27ca53 to your computer and use it in GitHub Desktop.
Save berdario/2bf439e3ac9ba2ecd3f8031a1a27ca53 to your computer and use it in GitHub Desktop.
import Data.Exists
data Showable_ a = Showable_ a
data Showable = Showable (Exists Showable_)
instance showable_ :: (Show a) => Show (Showable_ a) where
show (Showable_ x) = show x
instance showable :: (Show (Showable_ a)) => Show Showable where
show (Showable v) = runExists show' v
where
show' :: forall a. (Show a) => Showable_ a -> String
show' x = show x
showable :: forall a. (Show a) => a -> Showable
showable = Showable <<< mkExists <<< Showable_
[showable 1, showable "2"]
-- The `Show Showable` will result in the following error:
-- No type class instance was found for
-- Prelude.Show a0
-- in value declaration showable
-- where a0 is a rigid type variable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment