Difference between revisions of "To Squares With Functions Assignment"
Jump to navigation
Jump to search
Line 1: | Line 1: | ||
=Functions to Use= | =Functions to Use= | ||
==[https://smlfamily.github.io/Basis/list.html List Structure]== | ==[https://smlfamily.github.io/Basis/list.html List Structure]== | ||
− | * [https://smlfamily.github.io/Basis/list.html#SIG:LIST.nil:TY <nowiki>[]</nowiki>] | + | * [https://smlfamily.github.io/Basis/list.html#SIG:LIST.nil:TY <nowiki>[]</nowiki>] construct an empty list |
− | * [https://smlfamily.github.io/Basis/list.html#SIG:LIST.:::TY ::] | + | * [https://smlfamily.github.io/Basis/list.html#SIG:LIST.:::TY ::] construct a list out of a head element and a tail list |
− | * [https://smlfamily.github.io/Basis/list.html#SIG:LIST.null:VAL null] | + | * [https://smlfamily.github.io/Basis/list.html#SIG:LIST.null:VAL null] is the passed in list empty? |
− | * [https://smlfamily.github.io/Basis/list.html#SIG:LIST.hd:VAL hd] | + | * [https://smlfamily.github.io/Basis/list.html#SIG:LIST.hd:VAL hd] head element of the passed in list |
− | * [https://smlfamily.github.io/Basis/list.html#SIG:LIST.tl:VAL tl] | + | * [https://smlfamily.github.io/Basis/list.html#SIG:LIST.tl:VAL tl] tail list of the passed in list |
=Code to Implement= | =Code to Implement= |
Revision as of 14:51, 30 August 2024
Functions to Use
List Structure
- [] construct an empty list
- :: construct a list out of a head element and a tail list
- null is the passed in list empty?
- hd head element of the passed in list
- tl tail list of the passed in list
Code to Implement
file: | src/main/sml/warmup_squares_fun/my_length.sml | ![]() |
functions: | to_squares |
to_squares
A list of integers xs
is passed to to_squares
. Evaluate to a list where each item is the square of its counterpart in the passed list.
fun to_squares(xs : int list) : int list =
raise Fail "NotYetImplemented"
For example, if the passed list is [1,2,3,4]
then to_squares
would evaluate to [1, 4, 9, 16]
.
Test
source folder: | src/test/sml/warmup_squares_fun |
how to run with CM.make verbosity off: | sml -Ccm.verbose=false run_squares_fun_testing.sml |
how to run with CM.make verbosity on: | sml run_squares_fun_testing.sml |
note: ensure that you have removed all printing to receive credit for any assignment.