In the following, example1
is standard syntax (as documented), with Eq a
as a constraint. In example2
, I specify Eq a
dir
You could use named implementations:
[eq_nat] Eq Nat where { ... }
...
example_of_example2 : Type
example_of_example2 = example2 Nat eq_nat 3 3
A useful application of named implementations are defining multiple implementation of Monoid
:
[PlusNatSemi] Semigroup Nat where
(<+>) x y = x + y
[MultNatSemi] Semigroup Nat where
(<+>) x y = x * y
[PlusNatMonoid] Monoid Nat using PlusNatSemi where
neutral = 0
[MultNatMonoid] Monoid Nat using MultNatSemi where
neutral = 1
To comment : To get the default instance
getEq : (a : Type) -> {auto inst : Eq a} -> Eq a
getEq a {inst} = inst
Then you can have your default instance:
getEq (List Nat) -- => implementation of Eq...