Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free.

What are some techniques I might use to consistently refactor code removing the reliance on existential types? Typically these are used to disqualify undesired constructions of your type as well as to allow consumption with a minimal of knowledge about the given type (or so is my understanding).

Has anyone come up with a simple consistent way to remove reliance on these in code which still maintains some of the benefits? Or at least any ways of slipping in an abstraction that allows their removal without requiring significant code churn to cope with the alteration?

You can read more about existential types here ("if you dare..").

share|improve this question
3  
"First-Class Modules for Haskell" illustrates some key shortcomings of existential types, or at least the way Haskell currently implements them. In particular, an existentially-typed value always has to be accompanied by an ad-hoc wrapper, or GHC's brain will explode. Existential types are a little awkward in Haskell, but they're useful, and we don't have anything clearly better yet. –  Joey Adams Jan 27 '13 at 4:48
8  
@RobertHarvey I found the blog post that made me think about this question the first time: Haskell Antipattern: Existential Typeclass. Also, the paper Joey Adams mentions describes some poblems with existentials in Section 3.1. If you have contrary arguments, please share them. –  Petr Pudlák Jan 27 '13 at 8:10
4  
@PetrPudlák: Keep in mind that the antipattern there is not existential types in general, but a particular use of them when something simpler and easier (and better supported in Haskell) would do the same job. –  C. A. McCann Jan 28 '13 at 14:21
10  
If you want to know why the author of a particular blog post expressed an opinion then the person you should probably ask is the author. –  Eric Lippert Feb 25 '13 at 16:17
3  
@Ptolemy That's a matter of opinion. Using Haskell for years, I can't hardly imagine using a functional language that doesn't have a strong type system. –  Petr Pudlák Mar 7 at 21:00

1 Answer 1

I am not too familiar with Haskell, so I will try to answer the general part of the question as a non-academic functional C# developer.

After doing some reading, it turns out that:

1) Java wildcards are similar to existential types:

http://stackoverflow.com/questions/1031042/difference-between-scalas-existential-types-and-javas-wildcard-by-example?rq=1

2) Wildcards aren't implemented in C# completely: generic variance is supported, but call site variance is not:

http://stackoverflow.com/a/19284078/486561

3) You might not need this feature everyday, but when you do you will feel it (e.g. having to introduce an extra type to make things work):

http://stackoverflow.com/questions/8427353/wildcards-in-c-sharp-generic-constraints

Based on this information existential types / wildcards are useful when implemented properly and there is nothing wrong with them per se, but they can probably be misused just like other language features.

share|improve this answer

protected by Community Oct 31 '14 at 21:16

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.