Created
April 3, 2018 18:27
-
-
Save cocreature/ffc6d36e30b5c6edf4e702e5a31c3bc6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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