Skip to content

Instantly share code, notes, and snippets.

@zeldangit
Last active November 9, 2017 19:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zeldangit/3e8ab74c1af0a47e86d7aa2e42ad54d4 to your computer and use it in GitHub Desktop.
Save zeldangit/3e8ab74c1af0a47e86d7aa2e42ad54d4 to your computer and use it in GitHub Desktop.
:- module bank.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is det.
:- implementation.
:- import_module int, string, list.
/*
:- pred fib(int::in, int::out) is det.
fib(N, X) :-
( if N =< 2
then X = 1
else fib(N - 1, A), fib(N - 2, B), X = A + B
).
*/
:- type bank_account ---> account( name :: string,
account_no :: int,
funds :: float ).
:- pred get_arguments(io::di, io::uo, string::out) is det.
get_arguments(!IO, X) :-
io.read_line_as_string(Result, !IO),
(
Result = eof,
io.format("Goodbye!\n", [], !IO),
X = "null"
;
Result = ok(String),
X = String
;
Result = error(ErrorCode),
io.format("%s\n", [s(io.error_message(ErrorCode))], !IO),
X = "null"
).
main(!IO) :-
get_arguments(!IO, X),
io.format("echo: %s", [s(X)], !IO),
main(!IO).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment