You can make this work by using instance arguments, the Agda alternative to type classes. Unfortunately, the Agda library hasn't been written with instance arguments in mind (yet), so you have to define the Eq class and the instances for Char and String yourself:
open import Data.Bool
open import Data.Char hiding (_==_)
open import Data.String hiding (_==_)
-- The Eq type class
record Eq (A : Set) : Set₁ where
field
_==_ : A → A → Bool
-- Instance argument magic
open Eq {{...}}
-- Eq instance for Char
EqChar : Eq Char
EqChar = record { _==_ = Data.Char._==_ }
-- Eq instance for Bool
EqString : Eq String
EqString = record { _==_ = Data.String._==_ }
Now you can use _==_
for both Char
and Bool
:
test : Bool
test = ('a' == 'a') ∧ ("foo" == "foo")
To learn more about instance arguments, you can read about them on the Agda wiki (http://wiki.portal.chalmers.se/agda/pmwiki.php?n=ReferenceManual.InstanceArguments) or in the paper that introduced them (http://people.cs.kuleuven.be/~dominique.devriese/agda-instance-arguments/icfp001-Devriese.pdf).