:- module people.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is det.
:- implementation.
:- import_module string, list, int.

:- type sexes ---> male; female.
:- type person
    --->    person(
                name :: string,
                age :: int,
                sex :: sexes
            ).

:- func majority = int.
majority = 17.

:- func youth(person) = string.
youth(person(_, Age, male)) = (Age > majority -> "man"; "boy").
youth(person(_, Age, female)) = (Age > majority -> "woman"; "girl").

main(!IO) :-
    foldl(people.print, People, !IO),
    People = [
        person("Alice", 24, female),
        person("Bob", 42, male),
        person("Eve", 51, female),
        person("Malice", 15, male)
    ].

:- pred print(person::in, io::di, io::uo) is det.
print(P, !IO) :-
    io.format("%s is a %d-year-old %s\n",
        [s(P^name), i(P^age), s(youth(P))], !IO).