Use the [ name : Type ]
method of specifying a type to write the
function sub7
which takes in a number and subtracts 7 from it.l
Use the (: name Type)
method of specifying a type to write the
function triple
which takes in a number and triples it.
Use Typed Racket to write these functions. Make sure you write the output type as well as the input types.
sq18
: take in a number, square it, and subtract 18.sl5
: take in a string, return five more than its length.ssl
: take in two strings, find the sum of their lengths.Sometimes Number
is not restrictive enough. If you mean a number on
the number line, you have to tell Racket that you want a Real
number. Racket does know about complex numbers!
Write a function of two inputs that finds the absolute value of the difference between them.
Write a function that takes in two real numbers and returns the one
that is larger (try this using cond
or if
). Technical: Experiment to see
if you can use Number
as the type. (Why not?)