Last active
November 9, 2017 19:02
-
-
Save zeldangit/3e8ab74c1af0a47e86d7aa2e42ad54d4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:- 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