Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {-# 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))
Add Comment
Please, Sign In to add comment