Difference between revisions of "Remove First Assignment"
Jump to navigation
Jump to search
(→Test) |
|||
(5 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
+ | =Motivation= | ||
+ | Experience with equality types (along with more experience writing recursive functions with pattern matching). | ||
+ | |||
=Code to Implement= | =Code to Implement= | ||
− | {{SMLToImplement|remove_first|remove_first| | + | {{SMLToImplement|remove_first|remove_first|warmup_remove_first_occurrence}} |
==remove_first== | ==remove_first== | ||
− | fun remove_first(xs : ''a list, target : ''a) : ''a list = | + | <nowiki>fun remove_first(xs : ''a list, target : ''a) : ''a list = |
− | raise NotYetImplemented | + | raise NotYetImplemented</nowiki> |
− | Remove the first item which matches <code>target</code> if it exists. For example, <code>remove_first([1,2,3,4,5], 3)</code> should return the list [1,2,4,5]. | + | Remove the first item which matches <code>target</code> if it exists. For example, <code>remove_first([1,2,3,4,5], 3)</code> should return the list <code>[1,2,4,5]</code>. |
− | If the target does not exist, return the complete list. For example, <code>remove_first([1,2,3,4,5], 6)</code> should return the list [1,2,3,4,5]. | + | If the target does not exist, return the complete list. For example, <code>remove_first([1,2,3,4,5], 6)</code> should return the list <code>[1,2,3,4,5]</code>. |
=Test= | =Test= | ||
− | {{ | + | {{SMLUnitTesting|run_remove_first_testing|warmup_remove_first_occurrence}} |
Latest revision as of 05:42, 7 September 2022
Motivation
Experience with equality types (along with more experience writing recursive functions with pattern matching).
Code to Implement
file: | src/main/sml/warmup_remove_first_occurrence/remove_first.sml | |
functions: | remove_first |
remove_first
fun remove_first(xs : ''a list, target : ''a) : ''a list = raise NotYetImplemented
Remove the first item which matches target
if it exists. For example, remove_first([1,2,3,4,5], 3)
should return the list [1,2,4,5]
.
If the target does not exist, return the complete list. For example, remove_first([1,2,3,4,5], 6)
should return the list [1,2,3,4,5]
.
Test
source folder: | src/test/sml/warmup_remove_first_occurrence |
how to run with CM.make verbosity off: | sml -Ccm.verbose=false run_remove_first_testing.sml |
how to run with CM.make verbosity on: | sml run_remove_first_testing.sml |
note: ensure that you have removed all printing to receive credit for any assignment.