:- module(types, [
    type(list/1),
    type(float_format/0),
    type(normalisation_form/0),
    type(character_locale/0),
    type(integer/0),
    type(float/0),
    type(number/0),
    type(atom/0),
    char_code/2
   ]).

char_code(Char, Code) :-
    atom_codes(Char, [Code]).

:- module(prolog, [
    append/3,
    length/2,
    member/2,
    membechk/2,
    select/3
   ]).

:- import(types).

...

:- module(chars, [
    type(char/0),
    type(chars/0),
    all_lower/1,
    all_upper/1,
    float_chars/[2,3,4,5,6],
    integer_chars/[2,3,4],
    is_alnum/1,
    is_alpha/1,
    is_ascii/[1,2],
    is_blank/1,
    is_bracket/2,
    is_cntrl/1,
    is_csym/1,
    is_csymf/1,
    is_digit/[1,2],
    is_endfile/1,
    is_endline/1,
    is_graph/1,
    is_latin1/[1,2],
    is_lower/1,
    is_print/1,
    is_punct/1,
    is_quote/2,
    is_solo/1,
    is_symbol/1,
    is_unicode/[1,2],
    is_upper/1,
    is_xdigit/[1,2,3],
    locale_to_lower/[3,4],
    locale_to_title/[3,4],
    locale_to_upper/[3,4],
    next_character/[2,3,4],
    next_line/[2,3,4],
    next_sentence/[2,3,4],
    next_word/[2,3,4]
    normalise/[2,3,4],
    normalised/[1,2],
    normalised_compare/[3,4],
    number_chars/3,
    to_lower/[2,3],
    to_title/[2,3],
    to_upper/[2,3]
   ]).

:- import(types).

...

:- module(codes, [
    type(code/0),
    type(codes/0),
    all_lower/1,
    all_upper/1,
    float_codes/[2,3,4,5,6],
    integer_codes/[2,3,4],
    is_alnum/1,
    is_alpha/1,
    is_ascii/[1,2],
    is_blank/1,
    is_bracket/2,
    is_cntrl/1,
    is_csym/1,
    is_csymf/1,
    is_digit/[1,2],
    is_endfile/1,
    is_endline/1,
    is_graph/1,
    is_latin1/[1,2],
    is_lower/1,
    is_print/1,
    is_punct/1,
    is_quote/2,
    is_solo/1,
    is_symbol/1,
    is_unicode/[1,2],
    is_upper/1,
    is_xdigit/[1,2,3],
    locale_to_lower/[3,4],
    locale_to_title/[3,4],
    locale_to_upper/[3,4],
    next_character/[2,3,4],
    next_line/[2,3,4],
    next_sentence/[2,3,4],
    next_word/[2,3,4]
    normalise/[2,3,4],
    normalised/[1,2],
    normalised_compare/[3,4],
    number_codes/3,
    to_lower/[2,3],
    to_title/[2,3],
    to_upper/[2,3]
   ]).

:- import(types).

...

:- module(lists, [
  % append/3,		% in the 'prolog' module.
    append/5,
    append_append/6,
    append_append_length/7,
    append_length/[4,6],
    cons/3,
    findall_member/4,
    findall_member_append/5,
    foldl/4,
    foldl/5,
    foldl/6,
    foldl/7,
    foldr/4,
    foldr/5,
    foldr/6,
    foldr/7,
    head/2,
    last/[2,3],
  % length/2,		% in the 'prolog' module.
  % member/2,		% in the 'prolog' module.
    member_index/3,
    member_member/4,
    member_offset/3,
    memberchk/2,
    nextto/3,
    nonmember/2,
    one_longer/2,
    permutation/2,
    permutation_length/3,
    prefix/2,
    proper_prefix/2,
    proper_suffix/2,
    reverse/2,
    reverse_append/3,
    reverse_append_length/4,
    reverse_length/3,
    same_length/[2,3],
    scanl/4,
    scanl/5,
    scanl/6,
    scanl/7,
  % select/3,		% in the 'prolog' module.
    select/4,
    select_index/4,
    select_offset/4,
    selectchk/3,
    shorter_list/2,
    some/2,
    some/3,
    some/4,
    some/5,
    suffix/2,
    tail/2,
   ]).
:- meta_predicate
    foldl(3, +,          ?, ?),
    foldl(4, +, +,       ?, ?),
    foldl(5, +, +, +,    ?, ?),
    foldl(6, +, +, +, +, ?, ?),
    foldr(3, +,          ?, ?),
    foldr(4, +, +,       ?, ?),
    foldr(5, +, +, +,    ?, ?),
    foldr(6, +, +, +, +, ?, ?),
    scanl(3, +,          ?, ?),     
    scanl(4, +, +,       ?, ?),
    scanl(5, +, +, +,    ?, ?),
    scanl(6, +, +, +, +, ?, ?),
    some(1, +),
    some(2, +, +),
    some(3, +, +, +),
    some(4, +, +, +, +).

:- import(types).

...
foldl(    _, [],     R,  R).
foldl(    P, [A|As], R0, R) :-
    call( P,  A,     R0, R1),
    foldl(P,    As,  R1, R).

foldl(    _, [],     [],     R,  R).
foldl(    P, [A|As], [B|Bs], R0, R) :-
    call( P,  A,      B,     R0, R1),
    foldl(P,    As,     Bs,  R1, R).

foldl(    _, [],     [],     [],     R,  R).
foldl(    P, [A|As], [B|Bs], [C|Cs], R0, R) :-
    call( P,  A,      B,      C,     R0, R1),
    foldl(P,    As,     Bs,     Cs,  R1, R).

foldl(    _, [],     [],     [],     [],     R,  R).
foldl(    P, [A|As], [B|Bs], [C|Cs], [D|Ds], R0, R) :-
    call( P,  A,      B,      C,      D,     R0, R1),
    foldl(P,    As,     Bs,     Cs,     Ds,  R1, R).

foldr(    _, [],     R,  R).
foldr(    P, [A|As], R0, R) :- 
    foldr(P,    As,  R0, R1),  
    call( P,  A,     R1, R).   

foldr(    _, [],     [],     R,  R).
foldr(    P, [A|As], [B|Bs], R0, R) :-
    foldr(P,    As,     Bs,  R0, R1),
    call( P,  A,      B,     R1, R).

foldr(    _, [],     [],     [],     R,  R).
foldr(    P, [A|As], [B|Bs], [C|Cs], R0, R) :-
    foldr(P,    As,     Bs,     Cs,  R0, R1),
    call( P,  A,      B,      C,     R1, R).

foldr(    _, [],     [],     [],     [],     R,  R).
foldr(    P, [A|As], [B|Bs], [C|Cs], [D|Ds], R0, R) :-
    foldr(P,    As,     Bs,     Cs,     Ds,  R0, R1),
    call( P,  A,      B,      C,      D,     R1, R).

scanl(    _, [],     _,  []).
scanl(    P, [A|As], V0, [V1|Vs]) :-
    call( P,  A,     V0,  V1),
    scanl(P,    As,  V1,     Vs).

scanl(    _, [],     [],     _,  []).
scanl(    P, [A|As], [B|Bs], V0, [V1|Vs]) :-
    call( P,  A,      B,     V0,  V1),
    scanl(P,    As,     Bs,  V1,     Vs).

scanl(    _, [],     [],     [],     _,  []).
scanl(    P, [A|As], [B|Bs], [C|Cs], V0, [V1|Vs]) :-
    call( P,  A,      B,      C,     V0,  V1),
    scanl(P,    As,     Bs,     Cs,  V1,     Vs).

scanl(    _, [],     [],     [],     [],     _,  []).
scanl(    P, [A|As], [B|Bs], [C|Cs], [D|Ds], V0, [V1|Vs]) :-
    call( P,  A,      B,      C,      D,     V0,  V1),
    scanl(P,    As,     Bs,     Cs,     Ds,  V1,     Vs).

some(        P, [A|As]) :-
    (   call(P,  A)       
    ;   some(P,    As)    
    ).
      
some(        P, [A|As], [B|Bs]) :-
    (   call(P,  A,      B)       
    ;   some(P,    As,     Bs)    
    ).
      
some(        P, [A|As], [B|Bs], [C|Cs]) :-
    (   call(P,  A,      B,      C)       
    ;   some(P,    As,     Bs,     Cs)    
    ).
      
some(        P, [A|As], [B|Bs], [C|Cs], [D|Ds]) :-
    (   call(P,  A,      B,      C,      D)       
    ;   some(P,    As,     Bs,     Cs,     Ds)    
    ).
      
:- module(meta, [
    flip12/4,
    flip23/4,
    flip31/4
   ]).
:- meta_predicate
    flip12(3, ?, ?, ?),
    flip23(3, ?, ?, ?),
    flip31(3, ?, ?, ?).

flip12(P, B, A, C) :- call(P, A, B, C).
flip23(P, A, C, B) :- call(P, A, B, C).
flip31(P, C, B, A) :- call(P, A, B, C).

:- module(ordsets, [
    type(ordset/1),
    is_ordset/1,
    list_to_ordset/2,
    ord_compare/3,
    ord_disjoint/2,
    ord_disjoint_union/3,
    ord_intersect/2,
    ord_intersection/[2,3],
    ord_memberchk/2,
    ord_nonmember/2,
    ord_op/[4,5],
    ord_proper_subset/2,
    ord_proper_superset/2,
    ord_selectchk/3,
    ord_subset/2,
    ord_subtract/3,
    ord_superset/2,
    ord_symdiff/3,
    ord_union/[2,3,4]
   ]).

:- import(types).

...

:- module(queues, [
    type(queue/1),
    is_queue/1,
    cons_queue/3,
    head_queue/2,
    item_queue_append/3,
    list_queue_append/3,
    member_queue/2,
    member_queue_index/3,
    member_queue_offset/3,
    memberchk_queue/2,
    portray_queue/1,
    queue_empty/1,
    queue_item_append/3,
    queue_length/2,
    queue_list/2,
    queue_list_append/3,
    queue_list_length/3,
    tail_queue/2
   ]).

:- import(types).

...

:- module(numbers, [
    between/3,
    plus/3,
    succ/2
   ]).

:- import(types).

...
