Hi

I am trying to have an example on field selection and field 
update, but I get errors. Plz do let me know where there is an 
error in the code. Plz do explain it.
:- module upd.
:- interface.

:- import_module io.
:- pred main(io__state, io__state).
:- mode main(di, uo) is det.

:-type a.
:-type b.
:-type c.
:- type foo ---> f(a, b, c).

:- implementation.
:- import_module int, bool.
% Select the "a" field.
:- func get_a(foo) = a.
get_a(f(A, _, _)) = A.

% Update the "a" field.
:- func set_a(foo,a) = foo.
set_a(f(_, B, C), A) = f(A, B, C).


% Select the "b" field.
:- func get_b(foo) = b.
get_b(f(_, B, _)) = B.

% Update the "b" field.
:- func set_b(foo, b) = foo.
set_b(f(A, _, C), B) = f(A, B, C).


% Select the "c" field.
:- func get_c(foo) = c.
get_c(f(_, _, C)) = C.

% Update the "c" field.
:- func set_c(foo, c) = foo.
set_c(f(A, B, _), C) = f(A, B, C).

main --> do_while(getnext).

:- pred get_next(string::in, bool::out, io__state::di, 
io__state::uo) is det.
get_next(String, More) -->
 	io__read_word(get_a), { More = yes},
 		if get_a = ok then set_a = get_a else More = no,
 	io__read_word(get_b), {More =yes},
 		if get_b = ok then set_b = get_b else More = no,
 	io__read_word(get_c), {More = yes},
 		if get_c = ok then set_c = get_c else More = no.


Here are the errors:-
upd.m:046: Syntax error at token 'if': unexpected token at start 
of (sub)term.
upd.m:041: In clause for predicate `upd:main/2':
upd.m:041:   in argument 1 of call to predicate `do_while/3':
upd.m:041:   error: undefined symbol `getnext/0'.
upd.m:041: In clause for predicate `upd:main/2':
upd.m:041:   error: undefined predicate `do_while/3'.
upd.m:043: Error: no clauses for predicate `upd:get_next/4'.

--------------------------------------------------------------------------
mercury-users mailing list
post:  mercury-users@cs.mu.oz.au
administrative address: owner-mercury-users@cs.mu.oz.au
unsubscribe: Address: mercury-users-request@cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request@cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------

