Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alphabetical sort for Cmp instance #16

Open
etorreborre opened this issue Jun 1, 2018 · 0 comments
Open

Alphabetical sort for Cmp instance #16

etorreborre opened this issue Jun 1, 2018 · 0 comments

Comments

@etorreborre
Copy link

I am working on a variation of the typelevel Set (a set with possibly "missing" values). I would like to find a way to define a Cmp instance for 2 type a and b so that the result depends on the names of a and b. So far I was able to write

-- | taken from http://www.mchaver.com/posts/2017-12-12-type-name-to-string.html
type family TypeName a :: Symbol where
  TypeName Double = "Double"
  TypeName Int = "Int"
  TypeName String = "String"
  TypeName (M1 D ('MetaData name _ _ _) f ()) = name
  TypeName a = TypeName (Rep a ())

type family Cmp (a :: k) (b :: k) :: Ordering where
  Cmp a b = CmpSymbol (TypeName a) (TypeName b)

But this approach necessitates that a and b derive Generic is there another way to achieve a meaningful "default" comparison between Haskell types which does not require any constraint?

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant