I'm trying to write an SML function that takes as parameters a list and an item. If the item is present, the function should return a tuple containing the list without the first such occurence of that item and the item just removed. If there are no occurences of the item in the list, the function should return NONE or something similar to indicate this absence.
Asked
Active
Viewed 300 times
-1
-
Sounds like question 1 in the homework 2 in the Programming Language course in Coursera. If that is the case this would be a violation of the honor code: "My answers to homework, quizzes and exams will be my own work". – Edwin Dalorzo Oct 25 '13 at 12:43
1 Answers
2
Try this:
fun same_string(str, lst) =
case lst of
[] => NONE
|x::xs => case same_string(str, xs) of
NONE => if str = x
then SOME(xs)
else NONE
|SOME xs' => SOME (x :: xs')

user987339
- 10,519
- 8
- 40
- 45