Idris2/tests/idris2/interface019/LocalHints.idr
Edwin Brady 252292451f Add local hints (basic version)
This gives us the ability to define and use implementations locally, in
where clauses/local let bindings, as well as flag local definitions as
hints.
It's not yet quite equivalent to global hints, however, since it translated
the hint to a local let binding, which doesn't reduce, so if something
relies on the reduction behaviour of the hint, it won't work. This
refinement is coming later
2020-12-14 13:25:50 +00:00

49 lines
961 B
Idris

data Foo : Type where [noHints]
A : Foo
B : Foo
findA : {auto foo : Foo} -> String
findA {foo = A} = "Found an A"
findA {foo = _} = "Failed to find an A"
Baz : String -> Type
Baz s = s = "Found an A"
baz : (s : String ** Baz s)
baz = let %hint arg : Foo
arg = A
in (findA ** Refl)
interface Gnu where
constructor MkGnu
hasFoo : Foo
findB : Gnu => String
findB = case hasFoo of
B => "Found a B"
_ => "Failed to find a B"
Bar : String -> Type
Bar s = s = "Found a B"
bar : (s : String ** Bar s)
bar = let %hint arg : Gnu
arg = MkGnu B
in (findB ** Refl)
interface Gnat a where
constructor MkGnat
makeFoo : a -> Foo
record More where
constructor MkMore
0 Ty : Type
%unbound_implicits off
bug : forall a . a -> (s : String ** Bar s)
bug {a} x = let M : More
M = MkMore a
%hint arg : Gnat (Ty M)
arg = MkGnat (const B)
in (findB ** Refl)