in Education by
I read through the Wikipedia article Existential types. I gathered that they're called existential types because of the existential operator (∃). I'm not sure what the point of it is, though. What's the difference between T = ∃X { X a; int f(X); } and T = ∀x { X a; int f(X); } ? JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
When someone defines a universal type ∀X they're saying: You can plug in whatever type you want, I don't need to know anything about the type to do my job, I'll only refer to it opaquely as X. When someone defines an existential type ∃X they're saying: I'll use whatever type I want here; you won't know anything about the type, so you can only refer to it opaquely as X. Universal types let you write things like: void copy(List source, List dest) { ... } The copy function has no idea what T will actually be, but it doesn't need to know. Existential types would let you write things like: interface VirtualMachine { B compile(String source); void run(B bytecode); } // Now, if you had a list of VMs you wanted to run on the same input: void runAllCompilers(List<∃B:VirtualMachine<B>> vms, String source) { for (∃B:VirtualMachine vm : vms) { B bytecode = vm.compile(source); vm.run(bytecode); } } Each virtual machine implementation in the list can have a different bytecode type. The runAllCompilers function has no idea what the bytecode type is, but it doesn't need to; all it does is relay the bytecode from VirtualMachine.compile to VirtualMachine.run. Java type wildcards (ex: List<?>) are a very limited form of existential types. Update: Forgot to mention that you can sort of simulate existential types with universal types. First, wrap your universal type to hide the type parameter. Second, invert control (this effectively swaps the "you" and "I" part in the definitions above, which is the primary difference between existentials and universals). // A wrapper that hides the type parameter 'B' interface VMWrapper { void unwrap(VMHandler handler); } // A callback (control inversion) interface VMHandler { void handle(VirtualMachine vm); } Now, we can have the VMWrapper call our own VMHandler which has a universally-typed handle function. The net effect is the same, our code has to treat B as opaque. void runWithAll(List vms, final String input) { for (VMWrapper vm : vms) { vm.unwrap(new VMHandler() { public void handle(VirtualMachine vm) { B bytecode = vm.compile(input); vm.run(bytecode); } }); } } An example VM implementation: class MyVM implements VirtualMachine, VMWrapper { public byte[] compile(String input) { return null; // TODO: somehow compile the input } public void run(byte[] bytecode) { // TODO: Somehow evaluate 'bytecode' } public void unwrap(VMHandler handler) { handler.handle(this); } }

Related questions

0 votes
    Heteroassociative memory can be an example of which type of network? (a) group of instars (b) group of oustar ... group of instars or outstars Please answer the above question....
asked Sep 21, 2022 in Education by JackTerrance
0 votes
    Type of equality which says that every citizen has an equal right to participate in affairs of the State. Please answer the above question....
asked Aug 4, 2022 in Education by JackTerrance
0 votes
    The RangeValidator will fetch the value of the input and validate it with regex. Part of the regex is ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 16, 2022 in Education by JackTerrance
0 votes
    How would you write (in C/C++) a macro which tests if an integer type (given as a parameter) is ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 25, 2022 in Education by JackTerrance
0 votes
    Which of these return type of hasNext() method of an iterator? (a) Integer (b) Double (c) Boolean (d ... Collections Framework of Java Select the correct answer from above options...
asked Mar 1, 2022 in Education by JackTerrance
0 votes
    What type of variable can be defined in an interface? (a) public static (b) private final (c) public final ... & Packages of Java Select the correct answer from above options...
asked Feb 23, 2022 in Education by JackTerrance
0 votes
    What type of methods an interface contain by default? (a) abstract (b) static (c) final (d) private I ... & Packages of Java Select the correct answer from above options...
asked Feb 23, 2022 in Education by JackTerrance
0 votes
    Which of the following is not an Enterprise Beans type? (a) Doubleton (b) Singleton (c) Stateful (d) Stateless ... & JDBC of Java Select the correct answer from above options...
asked Feb 22, 2022 in Education by JackTerrance
0 votes
    Still new to Haskell, I have hit a wall with the following: I am trying to define some type ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 16, 2022 in Education by JackTerrance
0 votes
    Can someone tell me a easy method to check if a variable is a dictionary, list or anything else? I want to know ... is of which type. Select the correct answer from above options...
asked Jan 21, 2022 in Education by JackTerrance
0 votes
    Can anyone tell me what is the largest value of an int data type in the python? Select the correct answer from above options...
asked Jan 8, 2022 in Education by JackTerrance
0 votes
    Define the term solution. How many types of solutions are formed ? Write briefly about eaCHM type with an example. Select the correct answer from above options...
asked Jan 5, 2022 in Education by JackTerrance
0 votes
    What are emulsions ? What are their different types ? Give an example of each type ? Select the correct answer from above options...
asked Jan 3, 2022 in Education by JackTerrance
0 votes
    = A 1 * B14 is an example of which type of referencing? a. Relative b. Absolute c. Mixed d. None of these Select the correct answer from above options...
asked Dec 26, 2021 in Education by JackTerrance
0 votes
    Question 15: 15. .is a type of response test used in computing as an attempt to ensure that the response is ... code c) New code Select the correct answer from above options...
asked Dec 15, 2021 in Education by JackTerrance
...