]> gitweb @ CieloNegro.org - Lucu.git/blob - Data/Eq/Indirect.hs
3c93da25502a03df8143b8fa11d1a9f8ca3838fa
[Lucu.git] / Data / Eq / Indirect.hs
1 {-# LANGUAGE
2     FlexibleContexts
3   , TypeFamilies
4   , UnicodeSyntax
5   #-}
6 -- |Indirect equality comparison.
7 module Data.Eq.Indirect
8     ( Eq'(..)
9     , (==:)
10     , (/=:)
11     , (≡:)
12     , (≢:)
13     , (≠:)
14     )
15     where
16 import Prelude.Unicode
17
18 infix 4 ==:, /=:, ≡:, ≢:, ≠:
19
20 -- |Type class for indirectly equality-comparable types. That is, any
21 -- @α@ of @'Eq'' α@ has a monomorphism to some
22 -- equality-comparable type @γ@ while @α@ itself isn't
23 -- necessarily an instance of 'Eq'. This way we can generalise the
24 -- '==' operator so that it can take two different types as long as
25 -- they both have monomorphisms to the same 'Eq' type @γ@.
26 --
27 -- Minimal complete definition: 'Unified' and 'unify'.
28 class Eq (Unified α) ⇒ Eq' α where
29     -- |The said equality-comparable type @γ@.
30     type Unified α
31     -- |Monomorphism from @α@ to @γ@.
32     unify ∷ α → Unified α
33
34 -- |FIXME: doc
35 (==:) ∷ (Eq' α, Eq' β, Unified α ~ Unified β) ⇒ α → β → Bool
36 {-# INLINE (==:) #-}
37 (==:) = (∘ unify) ∘ (≡) ∘ unify
38
39 -- |FIXME: doc
40 (/=:) ∷ (Eq' α, Eq' β, Unified α ~ Unified β) ⇒ α → β → Bool
41 {-# INLINE (/=:) #-}
42 (/=:) = ((¬) ∘) ∘ (==:)
43
44 -- |FIXME: doc
45 (≡:) ∷ (Eq' α, Eq' β, Unified α ~ Unified β) ⇒ α → β → Bool
46 {-# INLINE CONLIKE (≡:) #-}
47 (≡:) = (==:)
48
49 -- |FIXME: doc
50 (≢:) ∷ (Eq' α, Eq' β, Unified α ~ Unified β) ⇒ α → β → Bool
51 {-# INLINE CONLIKE (≢:) #-}
52 (≢:) = (/=:)
53
54 -- |FIXME: doc
55 (≠:) ∷ (Eq' α, Eq' β, Unified α ~ Unified β) ⇒ α → β → Bool
56 {-# INLINE CONLIKE (≠:) #-}
57 (≠:) = (/=:)