Created
June 21, 2018 15:19
-
-
Save cocreature/d366b1e20021d1da07842fced5a6af24 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 FlexibleContexts #-} | |
{-# LANGUAGE RankNTypes #-} | |
{-# LANGUAGE ScopedTypeVariables #-} | |
{-# LANGUAGE UndecidableInstances #-} | |
module ReflectOrd where | |
import Data.Reflection | |
import Data.Proxy | |
newtype Ordable s a = Ordable { unordable :: a } | |
instance Reifies s (a -> a -> Ordering) => Eq (Ordable s a) where | |
Ordable a == Ordable b = reflect (Proxy :: Proxy s) a b == EQ | |
instance Reifies s (a -> a -> Ordering) => Ord (Ordable s a) where | |
compare (Ordable a) (Ordable b) = reflect (Proxy :: Proxy s) a b | |
f :: forall a x y. (Functor x, Functor y) => (a -> a -> Ordering) -> (forall b. Ord b => x b -> y b) -> x a -> y a | |
f f g xs = | |
reify f $ \(Proxy :: Proxy s) -> | |
fmap unordable (g (fmap (\x -> Ordable x :: Ordable s a) xs)) |
glguy
commented
Jun 21, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment