Frequently asked questions and answers of SML (Standard ML) in Artificial Intelligence and Machine Learning of Computer Science to enhance your skills, knowledge on the selected topic. We have compiled the best SML (Standard ML) Interview question and answer, trivia quiz, mcq questions, viva question, quizzes to prepare. Download SML (Standard ML) FAQs in PDF form online for academic course, jobs preparations and for certification exams .
Intervew Quizz is an online portal with frequently asked interview, viva and trivia questions and answers on various subjects, topics of kids, school, engineering students, medical aspirants, business management academics and software professionals.
Question-1. What is Standard ML?
Answer-1: Standard ML (SML) is a functional programming language with strong static typing and type inference.
Question-2. Who developed Standard ML?
Answer-2: Standard ML was developed by Robin Milner and others in the 1980s.
Question-3. What does "ML" stand for in Standard ML?
Answer-3: ML stands for "MetaLanguage."
Question-4. What is the purpose of Standard ML?
Answer-4: SML is designed for writing reliable, modular, and reusable code, often used in research and teaching.
Question-5. What type of language is SML?
Answer-5: SML is a functional, statically typed, and declarative language.
Question-6. What is type inference in SML?
Answer-6: Type inference allows SML to automatically deduce the types of expressions without explicit annotations.
Question-7. What is the basic structure of an SML program?
Answer-7: An SML program consists of expressions, declarations, and functions.
Question-8. How do you declare a variable in SML?
Answer-8: Use the val keyword, e.g., val x = 10;.
Question-9. How do you define a function in SML?
Answer-9: Use fun, e.g., fun add(x, y) = x + y;.
Question-10. What is a tuple in SML?
Answer-10: A tuple is an ordered collection of values, e.g., (1, "apple", true).
Question-11. How does SML handle immutability?
Answer-11: All variables in SML are immutable, meaning their values cannot change after declaration.
Question-12. What are patterns in SML?
Answer-12: Patterns are used to match the structure of data, e.g., in function definitions or case expressions.
Question-13. How do you create a list in SML?
Answer-13: Use square brackets, e.g., [1, 2, 3].
Question-14. What is the hd function in SML?
Answer-14: hd returns the first element of a list, e.g., hd [1, 2, 3] returns 1.
Question-15. What is the tl function in SML?
Answer-15: tl returns the list without the first element, e.g., tl [1, 2, 3] returns [2, 3].
Question-16. How do you append two lists in SML?
Answer-16: Use the @ operator, e.g., [1, 2] @ [3, 4].
Question-17. What is a record in SML?
Answer-17: A record is a collection of named fields, e.g., {name="Alice", age=25}.
Question-18. What is a datatype in SML?
Answer-18: A datatype is a user-defined type, e.g., `datatype color = Red
Question-19. What is the purpose of the case expression in SML?
Answer-19: case is used for pattern matching on data, e.g., `case x of 1 => "One"
Question-20. How do you define a recursive function in SML?
Answer-20: Use fun with recursion, e.g., `fun factorial 0 = 1
Question-21. What is the let expression in SML?
Answer-21: let allows local declarations, e.g., let val x = 10 in x + 20 end.
Question-22. What are exceptions in SML?
Answer-22: Exceptions are used to handle errors or unexpected situations, e.g., exception Error;.
Question-23. How do you raise an exception in SML?
Answer-23: Use the raise keyword, e.g., raise Error;.
Question-24. How do you handle exceptions in SML?
Answer-24: Use handle, e.g., expr handle Error => result.
Question-25. What is a signature in SML?
Answer-25: A signature is a module interface specifying types and values, e.g., sig val x: int end.
Question-26. What is a structure in SML?
Answer-26: A structure is a module that implements a signature, e.g., struct val x = 10 end.
Question-27. What is a functor in SML?
Answer-27: A functor is a module that takes other modules as parameters and returns a new module.
Question-28. How do you define a map function in SML?
Answer-28: Use a higher-order function, e.g., `fun map f [] = []
Question-29. What is the :: operator in SML?
Answer-29: :: is the cons operator, used to add an element to the front of a list, e.g., 1::[2,3].
Question-30. How do you calculate the length of a list in SML?
Answer-30: Use the length function, e.g., length [1, 2, 3].
Question-31. How do you check if a list is empty in SML?
Answer-31: Use the null function, e.g., null [] returns true.
Question-32. What is the Option type in SML?
Answer-32: Option is a type that can either be NONE or SOME(value).
Question-33. What is the foldl function in SML?
Answer-33: foldl applies a function left-to-right on a list, e.g., foldl op+ 0 [1, 2, 3].
Question-34. What is the foldr function in SML?
Answer-34: foldr applies a function right-to-left on a list, e.g., foldr op+ 0 [1, 2, 3].
Question-35. What is currying in SML?
Answer-35: Currying allows functions to take arguments one at a time, e.g., fun add x y = x + y;.
Question-36. How do you define a polymorphic function in SML?
Answer-36: Use type variables, e.g., fun id x = x;.
Question-37. What is the role of the val keyword in SML?
Answer-37: val declares and binds variables, e.g., val x = 10;.
Question-38. What is shadowing in SML?
Answer-38: Shadowing occurs when a new declaration with the same name as an existing one hides the old one.
Question-39. What is the purpose of the infix keyword?
Answer-39: infix defines custom infix operators, e.g., infix ++;.
Question-40. What is the ref type in SML?
Answer-40: ref creates mutable references, e.g., val x = ref 10;.
Question-41. How do you update a ref value in SML?
Answer-41: Use :=, e.g., x := 20;.
Question-42. How do you access a ref value in SML?
Answer-42: Use the ! operator, e.g., !x.
Question-43. What is tail recursion in SML?
Answer-43: Tail recursion ensures that recursive calls don't add to the call stack, improving efficiency.
Question-44. How do you import a library in SML?
Answer-44: Use the use function, e.g., use "library.sml";.
Question-45. What are equality types in SML?
Answer-45: Equality types ('a eqtype) support comparison using = and <>.
Question-46. What is the real type in SML?
Answer-46: real is a type for floating-point numbers, e.g., val pi:real = 3.14159;.
Question-47. How do you convert an int to a real in SML?
Answer-47: Use the real function, e.g., real 5.
Question-48. What are higher-order functions in SML?
Answer-48: Higher-order functions take other functions as arguments or return them as results.
Question-49. How does SML handle operator overloading?
Answer-49: Operators like + and * are overloaded for multiple types like int and real.
Question-50. What is the difference between fun and val for functions?
Answer-50: fun defines a function directly, while val can be used with anonymous functions (lambdas).
Frequently Asked Question and Answer on SML (Standard ML)
SML (Standard ML) Interview Questions and Answers in PDF form Online
SML (Standard ML) Questions with Answers
SML (Standard ML) Trivia MCQ Quiz