Appreciate some help #4:

tcklnbrg at at
Tue May 26 12:31:14 AEST 1998

% test.m----Please look at this example and tell me if I understand it. 
Thanks very much.

:- module test.
:- interface.
:- import_module io, string.
:- type classname ---> validateClassname(string).

:- pred validateClassname(string::in) is semidet.
:- pred javaclass(classname::in) is det.
:- pred main(io__state::di, io__state::uo) is det.

:- implementation.

validateClassname(S):- string__is_alpha(S).
% the actual javaclass clause would be read in at runtime.

main--> {javaclass(validateClassname("123"))}->
io__write_string("OK\n\n");  io__write_string("Failed\n\n").

/* the above prints "OK" implying that the function
is never called --compiler admits main
cannot fail.  

The module also compiles and runs without any definition for 
pred, validateClassname.  I have tested, also, that a string which would
fail the "is_alpha" test, including a "", also succeeds.

This would tend to imply, all-around, that any real type
validation can only occur for types defined as built-ins.

Do I get this right?  If so, what use is there for a type definition
like type ---> func(type) if func isn't used? Actually, why doesn't
Mercury require defining a pred for func?

As I understand it now, I really cannot do typechecking for types other
than built-ins.  Is this correct?  Would using typeclasses help?  If so,
where is the documentation for typeclasses?

Thanks for any help...continuing to hack along.

Ann Tecklenburg

More information about the users mailing list