mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-23 13:23:47 +00:00
Estimated hours taken: 0.1 tests/hard_coded/ho_func_reg.m Fix some errors in the function declarations found by Fergus' recent changes to prog_io.m.
42 lines
864 B
Mathematica
42 lines
864 B
Mathematica
|
|
% Regression test:
|
|
%
|
|
% This program uses a higher order function. Due to the way higher order
|
|
% types are represented as terms (which is quite different from any
|
|
% other type) manipulations of types that don't take this into account
|
|
% would make mistakes.
|
|
%
|
|
% The Mercury compiler of 20 December, 1996 failed to compile this,
|
|
% giving link errors.
|
|
|
|
:- module ho_func_reg.
|
|
|
|
:- interface.
|
|
|
|
:- import_module int, io.
|
|
|
|
:- pred main(io__state::di, io__state::uo) is det.
|
|
|
|
:- type bar == (func(int) = int).
|
|
:- inst bar = (func(in) = out is det).
|
|
|
|
:- func foo(bar, int) = int.
|
|
:- mode foo(in(bar), in) = out is det.
|
|
|
|
:- func next(int) = int.
|
|
|
|
:- implementation.
|
|
|
|
main -->
|
|
io__write_string("I seem to have compiled ok.\n"),
|
|
{ Eight = foo(next, 7) },
|
|
io__write_int(Eight),
|
|
io__write_string(" seems to be the answer\n").
|
|
|
|
next(I) = I + 1.
|
|
|
|
foo(F, I) = apply(F, I).
|
|
|
|
|
|
|