| 1 |
/* license: GNU Lesser General Public License Version 2.1 or later */ |
| 2 |
/* ------------------------------------------------------------------------- */ |
| 3 |
|
| 4 |
% pred make-modes-cl i:gref, i:list term, i:term, i:list (list hint-mode), i:list (list term), o:prop. |
| 5 |
% make-modes-cl T V (prod _ _ X) HintModes L (pi x\ C x):- |
| 6 |
% std.map HintModes (x\r\ [r|_] = x) FST, |
| 7 |
% std.map HintModes (x\r\ [_|r] = x) LAST, |
| 8 |
% pi x\ sigma NewL\ |
| 9 |
% std.map2 L FST (l\m\r\ if (m = mode-input) (r = [x | l]) (r = l)) NewL, |
| 10 |
% make-modes-cl T [x | V] (X x) LAST NewL (C x). |
| 11 |
% make-modes-cl T V _ _ L Clause :- |
| 12 |
% Ty = {coq.mk-app (global T) {std.rev V}}, |
| 13 |
% Clause = (pi s\ tc T Ty s :- std.forall L (x\ std.exists x var), !, coq.error "Invalid mode for" Ty). |
| 14 |
|
| 15 |
% takes the type of a class and build a list |
| 16 |
% of hint mode where the last element is mandatory |
| 17 |
func make-last-hint-mode-input term -> list hint-mode. |
| 18 |
make-last-hint-mode-input (prod _ _ (x\ (prod _ _ _) as T)) [mode-output | L] :- |
| 19 |
pi x\ make-last-hint-mode-input (T x) L. |
| 20 |
make-last-hint-mode-input (prod _ _ _) [mode-input]. |
| 21 |
make-last-hint-mode-input (sort _) []. |
| 22 |
|
| 23 |
% build a list of the seme langht as the the passed one |
| 24 |
% where all the elements are [] |
| 25 |
func build-empty-list list B -> list (list A). |
| 26 |
build-empty-list [] []. |
| 27 |
build-empty-list [_ | TL] [[] | L] :- |
| 28 |
build-empty-list TL L. |
| 29 |
|
| 30 |
% add the hint modes of a Class to the database. |
| 31 |
% note that if the Class has not specified hint mode |
| 32 |
% then we assume the hint mode to be - - - ... ! |
| 33 |
func add-modes gref ->. |
| 34 |
:if "add-modes" |
| 35 |
add-modes GR :- |
| 36 |
% the hint mode is added only if not exists |
| 37 |
if (not (tc.class GR _ _)) ( |
| 38 |
coq.env.typeof GR Ty, |
| 39 |
coq.hints.modes GR "typeclass_instances" ModesProv, |
| 40 |
if (ModesProv = []) (Modes = [{make-last-hint-mode-input Ty}]) (Modes = ModesProv), |
| 41 |
% make-modes-cl GR [] Ty Modes {build-empty-list Modes} Cl, |
| 42 |
% add-tc-db _ (after "firstHook") Cl, |
| 43 |
) true. |
| 44 |
add-modes _. |