Skip to content

Instantly share code, notes, and snippets.

@chessai
Created February 15, 2018 18:29
Show Gist options
  • Save chessai/430b803f141b7ab22b2aebee72b495e2 to your computer and use it in GitHub Desktop.
Save chessai/430b803f141b7ab22b2aebee72b495e2 to your computer and use it in GitHub Desktop.
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE TypeFamilies #-}
module Data.Type.Ord
( Compare
, OrdCase
, IsEQ
, IsLT
, IsGT
)
import Data.Bool (Bool(..))
import Data.Ord (Ordering(..))
type family Compare (l :: k) (r :: k) :: Ordering
type family OrdCase (x :: Ordering) (a :: k) (b :: k) (c :: k) :: k where
OrdCase LT a b c = a
OrdCase EQ a b c = b
OrdCase GT a b c = c
type IsLT t = OrdCase t True False False
type IsEQ t = OrdCase t False True False
type IsGT t = OrdCase t False False True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment