[mercury-users] An enumeration as a type: how to do it?

Fergus Henderson fjh at cs.mu.OZ.AU
Sun May 24 16:41:50 AEST 1998


Andrew Bromage wrote:
> 
> If you're only planning to convert in one direction, using a function may
> be a little syntactically cleaner:
> 
> :- func name_int_type(integral_type) = string.
> 
> name_int_type(byte) = "byte".
> name_int_type(short) = "short".
> name_int_type(int) = "int".
> name_int_type(long) = "long".
> name_int_type(char) = "char".

A simpler and more maintainable way of writing this is to use the
predicate functor/3 defined in the `std_util' module:

	name_int_type(Atom) = String :-
		functor(Atom, String, _Arity).

-- 
Fergus Henderson              | Designing grand concepts is fun;
fjh at cs.mu.oz.au               | finding nitty little bugs is just work.
http://www.cs.mu.oz.au/~fjh   | -- Brooks, in "The Mythical Man-Month".
PGP key fingerprint: 00 D7 A2 27 65 09 B6 AC  8B 3E 0F 01 E7 5D C4 3F



More information about the users mailing list