:- module play. :- interface. % synopsis: "The play is the thing ..." This module reflects an % exercise at the end of section 3.3 of Bratko's % /Prolog Programming for Artificial Intelligence, 3rd ed./, % enhanced with type information. op/3 is working nicely in % Mercury. % author: Douglas M. Auclair (DMA) % date: January 5, 2006 % % Just one question ... who is this 'geophf' person, anyway? :- import_module io. :- pred main(state::di, state::uo) is det. :- implementation. :- import_module list, int, string. :- type person ---> geophf; susan; jimmy; biff. :- type sport ---> go; rugby; basketball; football; volleyball; squash; halo; cricket. :- type sports ---> and(sport, sport). :- typeclass showable(T) where [ func show(T) = string ]. :- instance showable(person) where [ show(geophf) = "geophf", show(susan) = "Susan", show(jimmy) = "Jimmy", show(biff) = "Biff" ]. :- op(800, xfx, plays). % N.B.: op(720, xfy, and) is predefined in the Mercury language % Below are some "interesting" facts. jimmy plays football and squash. % 'Merkans call it "soccor" ... susan plays volleyball and basketball. % ... so the assertation: geophf plays halo and rugby. % "Boys play football; Men play Rugby" biff plays go and cricket. % can have different implications for % different people... main --> { jimmy plays What, Who plays halo and _, Susan plays _ and basketball }, print("Jimmy plays "), write(What), nl, % instead of the below, we could have discarded the typeclass % and simply wrote: 'write(Who), print(" plays halo\n").' &c. format("%s plays halo.\n ...huh? '%s'? Who's that?\n", [s(show(Who)), s(show(Who))]), format("%s plays basketball.\n", [s(show(Susan))]), % and one query ({ Biff plays go and cricket } -> format("%s plays go; which isn't exactly cricket, now, is it!", [s(show(Biff))]) ; print("What? No go? Is it tea time, then?")), nl.