Programming stile is a subject where the goal is to discover different way to program. Each of the src subfolder are a style of coding the same program. The program is a word counter. We have 2 type of input: -small (input-small.txt) -large (input-large.txt) In input the program takes in input also a stopword file (stop_words.txt). The goal is to filter out the stopword from the text in input and to count how many occurrencies of every single word appear; finally the program must return the top N words (th one that appear the most in the document) Given that this is a relative simple task, it became a little bit challenging when the teacher introduced constraint. For each style we have different one. This allow us to think about different ways (and not the most convinient and already known) way to resolve the problem.
| Language | Badge |
|---|---|
| Java | |
| JavaScript | |
| Haskell |
- The functions MUST do one computation at time
- In the main all the functions used to achieve the goal should be composed in a Pipeline Style
- Avoid (as much as we can) impure action
Variation of the Pipeline style, with the following additional constraints: - Each function takes an additional parameter, usually the last, which is another function. - The function parameter is applied at the end of the current function. - The function parameter is given, as input, what would be the output of the current function. - The larger problem is solved as a pipeline of functions, but where the next function to be applied is given as a parameter to the current function.
- Core program functions have no side effects of any kind, including IO.
- All IO actions must be contained in computation sequences that are clearly separated from the pure functions.
- All sequences that have IO must be called from the main program.
- Existence of an abstraction to which values can be converted. This abstraction provides operations to (1) wrap around values, so that they become the abstraction; (2) bind itself to functions, to establish sequences of functions.
- Larger problem is solved as a pipeline of functions bound together, with unwrapping happening at the end.
- Use “strong types”: avoid circumventing the type checker (e.g., avoid casts and avoid Object as a type).
- in this particular style we have got another class to compile before running the TermFrequency.java file, so before you need to do:
javac MyMonad.java
Javac TermFrequency
then
Java TermFrequency (input-small.txt / input-large.txt) n (n where n is a the top frequency word you want to retrieve; test was done with 2 for small-input and 25 for large one. Below ypu will find a list of the correct output)
node TermFreqeuncy (input-small.txt/input-large.txt) n
- To compile:
ghc TermFrequency.hs
- To run:
./TermFrequency < input-small.txt