Files
mercury/library/pair.m
Zoltan Somogyi a19bcaaed5 Updates to programming style in the library.
library/bt_array.m:
    Reorder the arguments of the resize and shrink predicates
    to make them easier to use with state variables.

tests/general/array_test.m:
    Update the test calls to these two predicates.

library/version_array2d.m:
    Rewrite part of this module using a programming style that includes
    variable names that are longer than one character :-(. In the absence
    of comprehensive, or even basic, test cases, leave the rest using
    the old style.

    Add a non-field-syntax lookup operation.

    Mark the site of a probable bug.

library/version_bitmap.m:
    Add non-field-syntax versions of the get_bit and set_bit operations.

NEWS.md:
    Announce the reordering and the new predicates above.

library/getopt.m:
library/getopt_io.m:
    Apply to getopt_io.m an update that was previously applied to getopt.m,
    even though getopt.m is now computed from getopt_io.m.

library/array2d.m:
library/bit_buffer.m:
library/bit_buffer.read.m:
library/bit_buffer.write.m:
library/bitmap.m:
library/cord.m:
library/edit_distance.m:
library/edit_seq.m:
library/fat_sparse_bitset.m:
library/fatter_sparse_bitset.m:
library/list.m:
library/one_or_more.m:
library/pair.m:
library/ra_list.m:
library/rbtree.m:
library/set_bbbtree.m:
library/set_ctree234.m:
library/set_ordlist.m:
library/set_tree234.m:
library/set_unordlist.m:
library/solutions.m:
library/sparse_bitset.m:
library/test_bitset.m:
library/thread.barrier.m:
library/thread.m:
library/thread.semaphore.m:
library/time.m:
library/tree_bitset.m:
library/version_array.m:
library/version_hash_table.m:
library/version_store.m:
    General updates to style, the main ones being the following.

    Using standard names for type variables:

    - K and V for key and value types in map-like structures
    - A to F for types of accumulators
    - T for most everything else, possibly with a numeric suffix
      to distinguish two separate types that nevertheless play
      similar roles.

    (I left descriptive type var names such as Stream and Store unchanged.)

    Adding or expanding descriptions of exported predicates and functions.

    Declaring and defining field syntax getters and setters without using ^,
    while keeping the use of field syntax, including ^, in the operations'
    descriptions.

    Defining field syntax operations operations in terms of the
    non-field-syntax versions, not vice versa.

    Defining function versions of operations in terms of the predicate
    versions, not vice versa.
2024-12-29 20:09:09 +11:00

59 lines
1.6 KiB
Mathematica

%---------------------------------------------------------------------------%
% vim: ft=mercury ts=4 sw=4 et
%---------------------------------------------------------------------------%
% Copyright (C) 1994-2006 The University of Melbourne.
% Copyright (C) 2014-2015, 2017-2018, 2024 The Mercury team.
% This file is distributed under the terms specified in COPYING.LIB.
%---------------------------------------------------------------------------%
%
% File: pair.m.
% Main author: fjh.
% Stability: high.
%
% The "pair" type. Useful for many purposes.
%
%---------------------------------------------------------------------------%
%---------------------------------------------------------------------------%
:- module pair.
:- interface.
:- type pair(T1, T2)
---> (T1 - T2).
:- type pair(T) == pair(T, T).
:- inst pair(I1, I2) for pair/2
---> (I1 - I2).
:- inst pair(I) == pair(I, I).
% Return the first element of the pair.
%
:- func fst(pair(T1, T2)) = T1.
:- pred fst(pair(T1, T2)::in, T1::out) is det.
% Return the second element of the pair.
%
:- func snd(pair(T1, T2)) = T2.
:- pred snd(pair(T1, T2)::in, T2::out) is det.
:- func pair(T1, T2) = pair(T1, T2).
%---------------------------------------------------------------------------%
%---------------------------------------------------------------------------%
:- implementation.
fst(X - _Y) = X.
fst(P, X) :-
X = fst(P).
snd(_X - Y) = Y.
snd(P, X) :-
X = snd(P).
pair(X, Y) = X - Y.
%---------------------------------------------------------------------------%
:- end_module pair.
%---------------------------------------------------------------------------%