Skip to content
This repository has been archived by the owner on Feb 2, 2021. It is now read-only.

Add functions to reflect Eq and Ord #6

Merged
merged 2 commits into from
Apr 25, 2018

Conversation

nfgrusk
Copy link
Contributor

@nfgrusk nfgrusk commented Apr 25, 2018

Is this okay? 🙂

compare (ReflectedOrd x) (ReflectedOrd y) =
reifiedCompare (reflect (Proxy :: Proxy s)) x y

reifyOrd :: forall a r. (a -> a -> Boolean) -> (a -> a -> Ordering) -> (forall s. (Reifies s (ReifiedOrd a)) => Proxy s -> r) -> r
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about implementing the eq function in terms of the compare function here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like this?

reifyOrd compare f = reify (ReifiedOrd eq compare) f
  where
    eq x y = case compare x y of
      EQ -> true
      _ -> false

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, exactly.

@paf31
Copy link
Owner

paf31 commented Apr 25, 2018

👍 Definitely, thanks!

@paf31 paf31 merged commit 79ab46e into paf31:master Apr 25, 2018
@paf31
Copy link
Owner

paf31 commented Apr 25, 2018

Great, thanks!

@nfgrusk nfgrusk deleted the implement-Eq-and-Ord branch April 26, 2018 06:03
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants