[mercury-users] Fact tables

David Overton dmo at cs.mu.OZ.AU
Fri Jul 18 12:26:18 AEST 2003


On Fri, Jul 18, 2003 at 12:15:22PM +1000, Michael Day wrote:
> 
> Hi,
> 
> To represent a relation that maps some ints to some other ints, which
> would be the best Mercury implementation:
> 
> :- pred encoding(int, int).
> :- mode encoding(in, out) is semidet.
> 
> :- pred encoding(int, maybe(int)).
> :- mode encoding(in, out) is det.
> 
> :- pred encoding(int, int).		% returns -1 on failure (ugh)
> :- mode encoding(in, out) is det.
> 
> The input does not form a contiguous range (although it may form multiple
> independent contiguous ranges).
> 
> Would using the fact_table pragma affect the implementation, or just the
> compilation speed? (presumably it would rule out using maybe(int)).

Well, you _could_ could still use maybe(int) if you wanted, you just put
a wrapper around the semidet version of the fact table:

	encoding(N, M) :-
		( encoding2(N, M0) ->
			M = yes(M0)
		;
			M = no
		).

	:- pred encoding2(int::in, int::out) is semidet.
	:- pragma fact_table(encoding2/2, ....).

`:- pragma fact_table' uses a completely different compilation process to
compiling normal predicates so the C code you end up with will be
different.  It basically generates a bunch of hash tables which will
probably be at least as efficient as the code generated for a normal
predicate, but there is no guarantee...



David
-- 
David Overton                  Uni of Melbourne     +61 3 8344 1354
dmo at cs.mu.oz.au                Monash Uni (Clayton) +61 3 9905 5779
http://www.cs.mu.oz.au/~dmo    Mobile Phone         +61 4 0337 4393
--------------------------------------------------------------------------
mercury-users mailing list
post:  mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the users mailing list