Skip to content

Instantly share code, notes, and snippets.

@nahiyan
Created November 28, 2018 04:54
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 nahiyan/4ea3181b6b4da9cb23556907301c7bd2 to your computer and use it in GitHub Desktop.
Save nahiyan/4ea3181b6b4da9cb23556907301c7bd2 to your computer and use it in GitHub Desktop.
// Copyright BDH Lab 2018
#include <iostream>
#include <string>
using std::cout;
using std::string;
// IO class
class IO {
string output;
public:
void setOutput(string output) {
this->output = output;
}
string getOutput() {
return this->output;
}
IO bind(IO io) {
IO binded;
binded.setOutput(this->output + io.getOutput());
return binded;
}
void execute() {
cout << output;
}
};
// IO text
IO text(string text) {
IO io;
io.setOutput(text);
return io;
}
// Functional core's main
IO main_() {
return text("Hello World!\n")
.bind(
text("Hi hi!\n"));
}
// Imperative shell's main
int main() {
main_().execute();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment