Frequently asked questions and answers of PureScript in Programming Technologies of Computer Science to enhance your skills, knowledge on the selected topic. We have compiled the best PureScript Interview question and answer, trivia quiz, mcq questions, viva question, quizzes to prepare. Download PureScript 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 PureScript?
Answer-1: PureScript is a strongly typed, purely functional programming language that compiles to JavaScript.
Question-2. Who created PureScript?
Answer-2: Phil Freeman created PureScript in 2013.
Question-3. What is the main advantage of using PureScript?
Answer-3: PureScript offers strong static typing, purity, and powerful type inference while being able to interoperate with JavaScript.
Question-4. How does PureScript compare to Haskell?
Answer-4: PureScript is similar to Haskell in syntax and type system but is designed to compile to JavaScript rather than machine code.
Question-5. How do you declare a variable in PureScript?
Answer-5: Using let, e.g., let x = 10.
Question-6. How do you define a function in PureScript?
Answer-6: Using = notation, e.g., add x y = x + y.
Question-7. How do you define a type in PureScript?
Answer-7: Using type, e.g., type Age = Int.
Question-8. What is the primary package manager for PureScript?
Answer-8: The primary package manager for PureScript is Spago.
Question-9. How do you install PureScript?
Answer-9: Using npm install -g purescript.
Question-10. How do you compile a PureScript file?
Answer-10: Using purs compile "*.purs".
Question-11. What is FFI in PureScript?
Answer-11: Foreign Function Interface (FFI) allows PureScript to interoperate with JavaScript.
Question-12. How do you write an FFI function in PureScript?
Answer-12: By defining a JavaScript function and linking it with foreign import in PureScript.
Question-13. What is the purpose of do notation in PureScript?
Answer-13: do notation is used for working with monads, making monadic code more readable.
Question-14. What are type classes in PureScript?
Answer-14: Type classes allow defining generic functions that work with multiple types.
Question-15. How do you declare a type class in PureScript?
Answer-15: Using class, e.g., class Show a where show :: a -> String.
Question-16. How do you create an instance of a type class?
Answer-16: Using instance, e.g., instance showInt :: Show Int where show x = ....
Question-17. What is the Maybe type in PureScript?
Answer-17: Maybe represents an optional value: Just a for a value or Nothing for no value.
Question-18. What are Functors in PureScript?
Answer-18: Functors allow mapping functions over wrapped values, e.g., map (+1) (Just 5).
Question-19. What are Applicative Functors in PureScript?
Answer-19: Applicatives allow applying wrapped functions to wrapped values, e.g., pure (+) <*> Just 2 <*> Just 3.
Question-20. What is a Monad in PureScript?
Answer-20: A Monad allows chaining computations with bind (>>=) or do notation.
Question-21. What is the difference between map and bind (>>=)?
Answer-21: map applies a function inside a wrapper, while bind chains computations that produce wrapped values.
Question-22. What is the role of Eff in PureScript?
Answer-22: Eff models side effects in PureScript?s type system.
Question-23. What is the Effect type in PureScript?
Answer-23: Effect is the modern replacement for Eff, used for handling side effects.
Question-24. How do you perform IO in PureScript?
Answer-24: Using Effect monad, e.g., main = log "Hello, PureScript!".
Question-25. What are Records in PureScript?
Answer-25: Records are extensible key-value structures, similar to JavaScript objects.
Question-26. How do you define a record in PureScript?
Answer-26: type Person = { name :: String, age :: Int }.
Question-27. How do you access a field in a record?
Answer-27: Using dot notation, e.g., person.name.
Question-28. What is Row Polymorphism in PureScript?
Answer-28: Row polymorphism allows records to have flexible field sets while maintaining type safety.
Question-29. How do you update a record field in PureScript?
Answer-29: Using `{ person
Question-30. What is newtype in PureScript?
Answer-30: newtype defines a type wrapper with no runtime overhead.
Question-31. How does data differ from newtype in PureScript?
Answer-31: data creates a separate data structure, while newtype is just a wrapper.
Question-32. What is the purpose of deriving in PureScript?
Answer-32: deriving automatically implements type class instances for a type.
Question-33. What is an Array in PureScript?
Answer-33: Array is a built-in list-like data structure.
Question-34. How do you create an array in PureScript?
Answer-34: Using square brackets, e.g., [1, 2, 3].
Question-35. How do you map over an array in PureScript?
Answer-35: Using map, e.g., map (*2) [1, 2, 3].
Question-36. How do you filter an array in PureScript?
Answer-36: Using filter, e.g., filter (_ > 2) [1, 2, 3].
Question-37. How do you concatenate two arrays in PureScript?
Answer-37: Using (++), e.g., [1, 2] ++ [3, 4].
Question-38. How do you find the length of an array?
Answer-38: Using length, e.g., length [1, 2, 3].
Question-39. How do you use pattern matching in PureScript?
Answer-39: case expressions, e.g., case x of 0 -> "zero"; _ -> "nonzero".
Question-40. What is the Either type in PureScript?
Answer-40: Either represents a computation that can fail: Left for failure, Right for success.
Question-41. What is Free monad in PureScript?
Answer-41: Free monad models composable effectful computations.
Question-42. What is Halogen in PureScript?
Answer-42: Halogen is a declarative UI framework for PureScript.
Question-43. What is Aff in PureScript?
Answer-43: Aff is an asynchronous effect monad for handling async computations.
Question-44. How do you perform asynchronous tasks in PureScript?
Answer-44: Using Aff, e.g., launchAff_ $ log "Async Task".
Question-45. What is QuickCheck used for in PureScript?
Answer-45: QuickCheck is used for property-based testing.
Question-46. What is the Prelude module in PureScript?
Answer-46: Prelude provides basic functions like arithmetic, booleans, and list operations.
Question-47. How do you define an alias for a complex type in PureScript?
Answer-47: Using type, e.g., type People = Array Person.
Question-48. How do you define a higher-order function in PureScript?
Answer-48: A function that takes another function as input, e.g., applyTwice f x = f (f x).
Question-49. How do you perform list comprehensions in PureScript?
Answer-49: Using do notation and guard, e.g., do x <- [1..10]; guard (even x); pure x.
Question-50. Why use PureScript over JavaScript?
Answer-50: PureScript offers strong typing, immutability, functional paradigms, and better maintainability while still compiling to JavaScript.
Frequently Asked Question and Answer on PureScript
PureScript Interview Questions and Answers in PDF form Online
PureScript Questions with Answers
PureScript Trivia MCQ Quiz