



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




How do signify a real in SML? - ANSWER>>> 12.0, 3e~2, 3,14e How do you signify a character in SML? - ANSWER>>> #"x", #"A", #\n" How do you concatenate two strings in SML? - ANSWER>>> Using the ^ operator i.e. "abra" ^ "cadabra" = "abracadabra" What operators can you not use on reals? - ANSWER>>> =, <> Can < and > be used on strings? - ANSWER>>> Yes, and it means lexicographically precedes. It returns a bool i.e. "a" < "b", "abc" < "acb" What are the 3 boolean operators? - ANSWER>>> not, andalso, orelse SML has what two types of typing? - ANSWER>>> Static and Strong How to cast as a real in SML? - ANSWER>>> real(11) = 11. How to round down, round up, round generally, and truncate? - ANSWER>>> floor(5.4) = 5 ceiling(5.4) = 6 round(5.5) = 6 trunc(~5.4) = ~ How to go from character to int? Vice-versa? - ANSWER>>> ord(#"0") = 48 chr(48) = #"0"
What is a tuple? - ANSWER>>> A fixed-size ordered collection of two or more values. Always same length, sometimes different types Ex: (1, "a", true) (4, (1,"a",true)) What is a list? - ANSWER>>> A list is a list of all the same type. Always same type, sometimes different length What are the return types of these list operations? Empty List [] Head hd Tail tl Append @ cons :: - ANSWER>>> 'a list 'a list→'a 'a list→'a list 'a list'a list→'a list 'a'a list→'a list What do explode and implode to? - ANSWER>>> Explode takes a string and converts it into a list of characters Implode takes a list of characters and makes it a string Fill in the blanks: SML is a(n) __________________-based (________________) language with ___________, ____________ typing - ANSWER>>> SML is an expression-based(functional) language with strong, static typing. Write a basic function that takes in a number and adds one - ANSWER>>> fun inc(x) = x+1;
Using the map function, subtract 3 from each element in the list - ANSWER>>> val sub3 = list_map(fn x => x-3); Using the filter function, filter a list so that only odd elements remain - ANSWER>>> val gt_filter = list_filter(fn x => x mod 2 >= 1); how to flip a list using fold? - ANSWER>>> fun reverse xs = foldl op:: nil xs; What does map do? - ANSWER>>> Applies an arbitrary function to each element and returns the resulting list What does filter do? - ANSWER>>> Selects elements from a list using an arbitrary predicate and returns the resulting list What does fold do? - ANSWER>>> Reduces a list to a single elements using an arbitrary function and initial value What does ''a mean? - ANSWER>>> That it is an equality type What is the type of list_map? - ANSWER>>> ('a - > 'b) - > 'a list - > 'b list What is the type of filter? - ANSWER>>> ('a - > bool) - > 'a list - > 'a list What is the type of foldr and foldl? - ANSWER>>> ('a*'b - > 'b) - > 'b - > 'a list - > 'b What does member do? - ANSWER>>> member is a function that checks to see if a number is in a list What is the type of member? - ANSWER>>> ''a list - > ''a - > bool What does intersection do? - ANSWER>>> Intersections checks through a list to see if a number in that list exists in the second list and returns a new list full of the interesecting numbers
What is the type of intersection and union? - ANSWER>>> ''a list * ''a list - > ''a list What does union do? - ANSWER>>> Union checks to see what numbers are not in the two lists and then returns a list of those numbers What is the type of remove_dups? - ANSWER>>> ''a list - > ''a list How do you create your own type? - ANSWER>>> datatype of (name here) = (Type) of (int, string, etc.) | (Type) of (int, string,etc.) Ex: datatype of card = Club of int | Diamond of int | Heart of int | Spade of int