This is the companion Github repository for the Haskell Data Series on Monday Morning Haskell! This series compares the basic construction of data types in Haskell, Java, and Python, so it has code samples in all three languares:
The code samples are fairly simple and easy to run, assuming you have the basic programs installed for each language.
Start by building the repository and loading up GHCI:
>> stack build
>> stack ghci
Then within GHCI, you can explore any of the individual modules. Since there are some overlapping types between the modules, you should first use the command :load
, and then you can load a single module. You are then free to .
> :load
> import Basic
> firstPerson
SimplePerson "Michael" "Smith" "msmith@gmail.com" 32 "Lawyer"
If you change any of the elements in the module, or add your own, you can also reload with :r
> :r
> firstPerson
SimplePerson "Mike" "Smith" "msmith@gmail.com" 32 "Lawyer"
The Java code modules are all written such that you can run each one's main
function as an executable. So given the source code:
public class Basic {
public static void main(String[] args) {
Person p = new Person("Jane", "Doe", "jane.doe@gmail.com", 35, "Project Manager");
System.out.println(p.getLastName());
}
}
You can see the output like so:
>> cd java
>> java Basic.java
Doe
The Python code works in much the same way as the Java code. Note though, that it uses Python3. Some of the code is incompatible with Python2.
>> cd python
>> python3 Basic.py
You can modify the "if name = main" portion and provide new definitions if you want above it:
if __name__ == "__main__":
p = Person("Jane", "Doe", "jane.doe@gmail.com", 35, "Project Manager")
print(p.occupation)