Skip to content

Instantly share code, notes, and snippets.

@cocreature
Created April 3, 2018 18:27
Show Gist options
  • Save cocreature/ffc6d36e30b5c6edf4e702e5a31c3bc6 to your computer and use it in GitHub Desktop.
Save cocreature/ffc6d36e30b5c6edf4e702e5a31c3bc6 to your computer and use it in GitHub Desktop.
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE UndecidableInstances #-}
module Convertible where
import Control.Applicative
import Data.Proxy
class Convertible a b where
convert :: a -> b
instance Convertible a b => Convertible (Const a x) (Const b y) where
convert = Const . convert . getConst
instance {-# OVERLAPPABLE #-} (a ~ b) => Convertible a b where
convert = id
apply :: forall a b proxy. (Convertible a b, Show b) => proxy b -> a -> IO ()
apply _ = print . (convert :: a -> b)
t :: Const String Int -> IO ()
t = apply (Proxy @(Const String Int))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment