:- module t.
:- interface.

:- import_module io.

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

:- implementation.

:- import_module require.
:- import_module string.
:- import_module type_desc.

:- type thing(T)
    --->    thing(T, int, string).

:- type ro
    --->    ro(int, int, int).

:- type rw
    --->    rw(int, string, int, string).

main(!IO) :-
    T = thing(rw(1, "2", 3, "4"), 5, "6"),
    what(T, What),
    io.write_string(What, !IO),
    io.nl(!IO).

:- pred what(thing(T)::in, string::out) is det.

what(T, What) :-
    ( dynamic_cast(T, _ : thing(ro)) ->
        What = "ro"
    ; dynamic_cast(T, _ : thing(rw)) ->
        What = "rw"
    ;
        unexpected($module, $pred, string(type_of(T)))
    ).

%-----------------------------------------------------------------------------%
% vim: ft=mercury ts=4 sts=4 sw=4 et
