Difference between revisions of "Sum Distances To Origin With Pattern Matching Compared To Java Assignment"
Jump to navigation
Jump to search
(→Java) |
(→SML) |
||
Line 29: | Line 29: | ||
==SML== | ==SML== | ||
+ | |||
+ | Fall 2022 Note: if attempted without pattern matching, you may receive an unresolved flex record error: | ||
+ | |||
+ | ../../../main/sml/warmup_sum_distances_to_origin/sum_distances_to_origin.sml:4.2-21.56 Error: unresolved flex record (need to know the names of ALL the fields | ||
+ | in this context) | ||
+ | type: {1:real, 2:real; 'Z} | ||
+ | |||
+ | this can be solved by using pattern matching or specifying the type of the parameter xys: | ||
+ | |||
+ | fun sum_distances_to_origin(xys : (real * real) list) | ||
+ | |||
{{SMLToImplement|sum_distances_to_origin|sum_distances_to_origin|warmup_sum_distances_to_origin}} | {{SMLToImplement|sum_distances_to_origin|sum_distances_to_origin|warmup_sum_distances_to_origin}} | ||
[https://smlfamily.github.io/Basis/math.html#SIG:MATH.sqrt:VAL Math.sqrt(v)] | [https://smlfamily.github.io/Basis/math.html#SIG:MATH.sqrt:VAL Math.sqrt(v)] | ||
− | fun sum_distances_to_origin(xys) | + | fun sum_distances_to_origin(xys : (real * real) list) |
=Test= | =Test= |
Revision as of 21:52, 3 September 2022
Background
a^2 + b^2 = c^2
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
Fall 2022 Note: if attempted without pattern matching, you may receive an unresolved flex record error:
../../../main/sml/warmup_sum_distances_to_origin/sum_distances_to_origin.sml:4.2-21.56 Error: unresolved flex record (need to know the names of ALL the fields in this context) type: {1:real, 2:real; 'Z}
this can be solved by using pattern matching or specifying the type of the parameter xys:
fun sum_distances_to_origin(xys : (real * real) list)
file: | src/main/sml/warmup_sum_distances_to_origin/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 |
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.