Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New #3

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ml_lab.questions.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<firstname> <lastname>
Ashlan Olson
CSCI 305
Spring 2018
Lab Questions
Expand Down
40 changes: 38 additions & 2 deletions ml_lab.sml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,48 @@
*
* CSCI 305 - ML Programming Lab
*
* <firstname> <lastname>
* <email-address>
* Ashlan Olson
* ashlan.olson@outlook.com
*
***************************************************************)

(* Define your data type and functions here *)
fun f[] = [] (*if the input is an empty list, it will return empty list*)
| f (x::xs) = (x + 1) :: (f xs); (*x is head of list, xs is tail; adds 1
to x and then uses recursion to add 1 to xs*)

datatype 'element set =
Empty | Set of 'element * 'element set;

fun isMember e Empty = false

| isMember e (Set(x, xs)) =
if (e = x) then true
else isMember e xs;


fun list2Set []= Empty

| list2Set (x::xs) =
let fun dupl [] = Empty
| dupl (x::xs) = Set(x, dupl(xs))
in
if isMember x (dupl(xs)) then list2Set xs
else
Set(x,list2Set(xs))
end;

fun union set1 Empty = set1
| union Empty set2 = set2
| union (Set(x, xs)) set2 =
if isMember x set2 then union xs set2
else Set(x, union xs set2);

fun intersect set1 Empty = Empty
| intersect Empty set2 = Empty
| intersect (Set(x, xs)) set2 =
if isMember x set2 then Set(x, intersect xs set2) else
intersect xs set2;

(* Simple function to stringify the contents of a Set of characters *)
fun stringifyCharSet Empty = ""
Expand Down