Difference between revisions of "Sum Distances To Origin With Pattern Matching Compared To Java Assignment"
Jump to navigation
Jump to search
Line 3: | Line 3: | ||
=Previous Warmup= | =Previous Warmup= | ||
− | [[#Sum_Distances_To_Origin_With_Functions_Assignment | + | [[#Sum_Distances_To_Origin_With_Functions_Assignment]] |
=Background= | =Background= |
Revision as of 02:24, 9 September 2022
Contents
Motivation
Compare implementations in Java and SML to highlight the crispness of type inference and pattern matching.
Previous Warmup
#Sum_Distances_To_Origin_With_Functions_Assignment
Background
SML
Java
Code To Implement
Java
Note: you will need to complete the ImList<E> exercise before testing the Java portion of this assignment.
class: | SumDistancesToOrigin.java | ![]() |
methods: | sumDistancesToOrigin | |
package: | distance.warmup | |
source folder: | src/main/java |
public static double sumDistancesToOrigin(ImList<ImTuple2<Double, Double>> xys)
SML
file: | src/main/sml/warmup_sum_distances_to_origin_pattern/sum_distances_to_origin.sml | ![]() |
functions: | sum_distances_to_origin |
fun sum_distances_to_origin(xys : (real * real) list)
Test
Java
class: | SumDistancesToOriginTestSuite.java | ![]() |
package: | distance.warmup | |
source folder: | src/test/java |
SML
source folder: | src/test/sml/warmup_sum_distances_to_origin_pattern |
how to run with CM.make verbosity off: | sml -Ccm.verbose=false run_sum_distances_to_origin_testing.sml |
how to run with CM.make verbosity on: | sml run_sum_distances_to_origin_testing.sml |
note: ensure that you have removed all printing to receive credit for any assignment.