How to declare a function suffixsen : string list -> string list ???
Tnx.
How to declare a function suffixsen : string list -> string list ???
Tnx.
The syntax to define a function with one argument in sml is:
fun functionName argumentName = functionBody
or
fun functionName (argumentName : argumentType) = functionBody
if you want to specify the type explicitly. So to define a function named suffixsen
of type string list -> string list
, you can do:
fun suffixsen (strings : string list) = someExpressionThatReturnsAStringList
Edit in response to you comment:
In order to append "son" to each string in the list, you should look at the ^
operator[1], which concatenates string, and the map
function which performs an operation for each element in a list.
[1] http://www.standardml.org/Basis/string.html#SIG:STRING.^:VAL
(copy and paste this link in your browser - for some reason I can't get this to be clickable)
After declaring types inside the parens, declare the function's return type on the outside with :return-type
. At leat in SMLnj. I found this through trial and error, can't find documentation for it.
fun suffixson (xs: string list ): string list =
map (fn x => x ^ "son") xs