Tell me more ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I've sometimes heard that using existential data types is sort of a bad practice in functional programming and that there are ways how to avoid it. I'd like to know, if it is really true, what are the reasons for (not) using existentials, and perhaps how to convert common code patterns that use them into patterns that don't.

share|improve this question
4  
I've sometimes heard that using existential data types is sort of a bad practice -- Citation, please. I did a bit of research on Google, and couldn't find a single instance of someone saying they were bad. In fact, most people are quite complimentary about them. – Robert Harvey Jan 27 at 1:07
2  
"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 at 4:48
6  
@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 at 8:10
2  
@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 at 14:21
2  
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 at 16:17
show 4 more comments

closed as not constructive by Eric Lippert, gnat, Mike Brown, GlenH7, Martijn Pieters Feb 25 at 18:44

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or specific expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, see the FAQ for guidance.