Skip to content

Instantly share code, notes, and snippets.

@jkarni
Last active September 3, 2015 00:32
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 jkarni/8d24a13b4be4cbbb1373 to your computer and use it in GitHub Desktop.
Save jkarni/8d24a13b4be4cbbb1373 to your computer and use it in GitHub Desktop.
{-# LANGUAGE ConstraintKinds #-}
module Main where
import Data.Constraint
show' :: (Maybe (Dict (Show a))) -> a -> String
show' (Just Dict) x = show x
show' Nothing _ = "<<not showable>>"
t1 = show' (Just Dict) 5
-- "5"
t2 = show' Nothing id
-- "<<not showable>>"
-- Doesn't typecheck
-- t3 = show' (Just Dict) id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment