[mercury-users] How to transform `semidet' to `det' ?
David Overton
dmo at cs.mu.OZ.AU
Wed Jul 25 17:17:43 AEST 2001
On Wed, Jul 25, 2001 at 08:23:11AM +0200, Holger Krug wrote:
> I've added an option "--unique-state" to the moose parser generator to
> allow values allowing only unique references (like those of type
> io__state) to be used as parser_state. I'll post the changes of having
> finished the necessary tests. I the course of modifying moose I
> encountered the following problem:
>
> I had to change the determinism of some of the moose procedures from
> `semidet' to `det'. Those procedures originally where defined to work
> on state and rule numbers of type `int'. Some of those state and rule
> numbers where declared to be input parameters. Because there is only a
> finite number of states and rules the original versions of the
> procedures were `semidet'. To be able to declare them as `det' I generated
> new type definitions like:
>
> :- type rule_num
> ---> rule0x1
> ; rule0x2
> ; rule0x3
> ; rule0x4
> ; rule0x5
> ; rule0x6
> ; rule0x7
> ; rule0x8
> .
>
> :- type state_num
> ---> state0x0
> ; state0x1
> ; state0x2
> ; state0x3
> ; state0x4
> ; state0x5
> ; state0x6
> ; state0x7
> ; state0x8
> ; state0x9
> ; state0xa
> .
>
> The parameter types of the procedures in question I redeclared to
> be `rule_num' resp. `state_num'.
>
> My questions now are:
>
> * Is there any runtime performance overhead linked with my modifications?
> (Obviously there is a compile time performance overhead, because the
> new types could be really enormous discriminated unions.) Will there
> be any runtime performance overhead in future versions of the Mercury
> compiler? (The question, in short, is: Is the current or a future version
> of the Mercury compiler able to translate the enumerations `rule_num'
> resp. `state_num' as `int'?)
Enumeration types are represented as integers so there will be no
runtime performance overhead.
> * Are there other ways to change the determinism of procedures from `semidet'
> to `det'? All procedures in question have input and output parameters and
> should work only on a sub-type of the declared input types.
Yes, you could create an inst, e.g.
:- inst rule_num == bound(1 ; 2 ; 3 ; 4 ; 5 ; 6 ; 7 ; 8).
and then use 'in(rule_num)' and 'out(rule_num)' instead of 'in' and
'out', in mode declarations for parameters of this type.
Another alternative is to wrap the body of the predicate in an
if-then-else and call 'error' if it fails.
David
--
David Overton Department of Computer Science & Software Engineering
PhD Student The University of Melbourne, Victoria 3010, Australia
+61 3 8344 9159 http://www.cs.mu.oz.au/~dmo
--------------------------------------------------------------------------
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