Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
5
Task/Variables/Mercury/variables-1.mercury
Normal file
5
Task/Variables/Mercury/variables-1.mercury
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
:- func name = string.
|
||||
name = Name :-
|
||||
Name = Title ++ " " ++ Given,
|
||||
Title = "Dr.",
|
||||
Given = "Bob".
|
||||
4
Task/Variables/Mercury/variables-2.mercury
Normal file
4
Task/Variables/Mercury/variables-2.mercury
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
:- pred greet(string::in, io::di, io::uo) is det.
|
||||
greet(Who, !IO) :-
|
||||
io.write_string("Hello", !IO),
|
||||
io.format(", %s!\n", [s(Who)], !IO).
|
||||
4
Task/Variables/Mercury/variables-3.mercury
Normal file
4
Task/Variables/Mercury/variables-3.mercury
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
:- pred greet(string::in, io::di, io::uo) is det.
|
||||
greet(Who, !.IO, !:IO) :-
|
||||
io.write_string("Hello", !.IO, !:IO),
|
||||
io.format(", %s!\n", [s(Who)], !.IO, !:IO).
|
||||
4
Task/Variables/Mercury/variables-4.mercury
Normal file
4
Task/Variables/Mercury/variables-4.mercury
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
:- pred greet(string::in, io::di, io::uo) is det.
|
||||
greet(Who, IO0, IO) :-
|
||||
io.write_string("Hello", IO0, IO1),
|
||||
io.format(", %s!\n", [s(Who)], IO1, IO).
|
||||
9
Task/Variables/Mercury/variables-5.mercury
Normal file
9
Task/Variables/Mercury/variables-5.mercury
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
:- func dr(string) = string.
|
||||
dr(Name) = Titled :-
|
||||
some [!SB] (
|
||||
!:SB = string.builder.init,
|
||||
put_char(handle, 'D', !SB),
|
||||
put_char(handle, 'r', !SB),
|
||||
format(handle, " %s", [s(Name)], !SB),
|
||||
Titled = to_string(!.SB)
|
||||
).
|
||||
6
Task/Variables/Mercury/variables-6.mercury
Normal file
6
Task/Variables/Mercury/variables-6.mercury
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
% all_under(N, L)
|
||||
% True if every member of L is less than N
|
||||
%
|
||||
:- pred all_under(int::in, list(int)::in) is semidet.
|
||||
all_under(Limit, L) :-
|
||||
all [N] (member(N, L) => N < Limit).
|
||||
23
Task/Variables/Mercury/variables-7.mercury
Normal file
23
Task/Variables/Mercury/variables-7.mercury
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
:- type accumulator == (pred(int, int, io, io)).
|
||||
:- inst accumulator == (pred(in, out, di, uo) is det).
|
||||
|
||||
:- func accumulator >> accumulator = accumulator.
|
||||
:- mode in(accumulator) >> in(accumulator) = out(accumulator).
|
||||
A >> B = C :-
|
||||
C = (pred(!.N::in, !:N::out, !.IO::di, !:IO::uo) is det :-
|
||||
A(!N, !IO),
|
||||
B(!N, !IO)).
|
||||
|
||||
:- pred add(int::in, int::in, int::out, io::di, io::uo) is det.
|
||||
add(N, !Acc, !IO) :-
|
||||
io.format("adding %d to accumulator (current value: %d)\n",
|
||||
[i(N), i(!.Acc)], !IO),
|
||||
!:Acc = !.Acc + N.
|
||||
|
||||
:- pred example2(io::di, io::uo) is det.
|
||||
example2(!IO) :-
|
||||
F = add(5)
|
||||
>> add(5)
|
||||
>> add(-10),
|
||||
F(0, X, !IO),
|
||||
io.print_line(X, !IO).
|
||||
39
Task/Variables/Mercury/variables-8.mercury
Normal file
39
Task/Variables/Mercury/variables-8.mercury
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
:- module evenodd.
|
||||
:- interface.
|
||||
:- import_module io.
|
||||
:- pred main(io::di, io::uo) is det.
|
||||
:- implementation.
|
||||
:- import_module list, string.
|
||||
|
||||
:- type coin
|
||||
---> heads
|
||||
; tails.
|
||||
|
||||
:- inst heads for coin/0
|
||||
---> heads.
|
||||
:- inst tails for coin/0
|
||||
---> tails.
|
||||
|
||||
main(!IO) :-
|
||||
(if heads(heads, N) then
|
||||
print_heads(N, !IO)
|
||||
else true).
|
||||
|
||||
:- pred print_heads(coin::in(heads), io::di, io::uo) is det.
|
||||
print_heads(_, !IO) :-
|
||||
io.write_string("heads\n", !IO).
|
||||
|
||||
:- pred print_tails(coin::in(tails), io::di, io::uo) is det.
|
||||
print_tails(_, !IO) :-
|
||||
io.write_string("tails\n", !IO).
|
||||
|
||||
:- pragma foreign_export_enum("C", coin/0, [prefix("COIN_"), uppercase]).
|
||||
|
||||
:- pred heads(coin::in, coin::out(heads)) is semidet.
|
||||
:- pragma foreign_proc("C",
|
||||
heads(N::in, M::out(heads)),
|
||||
[promise_pure, will_not_call_mercury],
|
||||
"
|
||||
M = N;
|
||||
SUCCESS_INDICATOR = N == COIN_HEADS;
|
||||
").
|
||||
Loading…
Add table
Add a link
Reference in a new issue