Questions 1. [8-pts] Using your knowledge of algebraic data types, answer the fo
ID: 3595175 • Letter: Q
Question
Questions 1. [8-pts] Using your knowledge of algebraic data types, answer the following short-answer questions: 1. What is the cardinality of the set int32? 2. Give an example of a commonly used product-type from type algebra. Give it's type algebraic description, and a type constructor in the C++17 standard library that implements it. [Hint: we've seen examples in class, you dont need to go looking online] 3. Give an example of a commonly used sum-type from type algebra. Give it's type algebraic description, and a type constructor in C++17 standard library that implements it. Hint: we ve seen examples in class, you don't need to go looking online] 4. Write a type algebraic expression for the following structure: struct int a; std::variantcint, bool> v 2. [8-pts] Using your knowledge of functions, answer the following questions 1. Under which conditions can a function be 'memoized'? 2. Explain how the set of functions TT, for some type T, form a monoid under composition. 3. Briefly describe how composition of functions can lead to linear complexity scaling in software construction. 4. How does the functor pattern contribute to function composition? software abstractions. Give some examples. std: :sort to sort the list in order from shortest vecR2 to longest. You must use a lambda 3. [4-pts] Speculate briefly on why abstractions derived from nature provide the most productive 4. [5-amnesty] Suppose we have a list vs std: vector«vecR2Explanation / Answer
int and Int32 are indeed synonymous; int will be a little more familiar looking, Int32makes the 32-bitness more explicit to those reading your code.
In C#, int is mapped to Int32.
It is a value type and represents System.Int32 struct.
It is signed and takes 32 bits.
It has minimum -2147483648 and maximum +2147483647 value.
------------------------------------------------------------------------------------------------
[1]-2)
A type corresponding to product type is multiplication (Mul)
That is, the type a · b is a container holding both an a and a b. The counting argument justifies the correspondence with multiplication - if we fix a and b to both be Bool, the possible values of the type Mul Bool Bool are
---------------------------------------------------------------------------------------------------------------------
[1]-3)
Rust/Swift enums are “sum types”
bcz they are the sum of the two sets.
enum Foo
{
Bool(bool), Integer(u8),
}
is a set of all values which are valid booleans, and all values which are valid integers. This is a sum of sets Foo= Bool+u8
-----------------------------------------------------------------------------------------------------------------------
[1]-4)
The class template std::variant represents a type-safe union.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.