Guest User

Untitled

a guest
Jun 22nd, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. {-# LANGUAGE FlexibleContexts #-}
  2. {-# LANGUAGE RankNTypes #-}
  3. {-# LANGUAGE ScopedTypeVariables #-}
  4. {-# LANGUAGE UndecidableInstances #-}
  5. module ReflectOrd where
  6. import Data.Reflection
  7. import Data.Proxy
  8.  
  9. newtype Ordable s a = Ordable { unordable :: a }
  10.  
  11. instance Reifies s (a -> a -> Ordering) => Eq (Ordable s a) where
  12. Ordable a == Ordable b = reflect (Proxy :: Proxy s) a b == EQ
  13.  
  14. instance Reifies s (a -> a -> Ordering) => Ord (Ordable s a) where
  15. compare (Ordable a) (Ordable b) = reflect (Proxy :: Proxy s) a b
  16.  
  17. f :: forall a x y. (Functor x, Functor y) => (a -> a -> Ordering) -> (forall b. Ord b => x b -> y b) -> x a -> y a
  18. f f g xs =
  19. reify f $ \(Proxy :: Proxy s) ->
  20. fmap unordable (g (fmap (\x -> Ordable x :: Ordable s a) xs))
Add Comment
Please, Sign In to add comment