This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE GADTs, RankNTypes, TypeFamilies, DataKinds, PolyKinds, TypeOperators, ScopedTypeVariables #-} | |
-- Lots of ways you can phrase this, but this works for me | |
-- For folks who haven't seen it before, this is "the essence of the sum type" and sigma stands for sum. | |
-- You see it far more often in dependent types than elsewhere because it becomes a lot more pleasant to | |
-- work with there, but it's doable in other contexts too. Think of the first parameter to the data | |
-- constructor as a generalized "tag" as we talk about in "tagged union", and the second parameter is the | |
-- "payload". It turns out that you can represent any simple sum type you could write in Haskell this way | |
-- by using a finite and enumerable `f`, but things can get more unusual when `f` isn't either. In such | |
-- cases, it's often easier to think of this as the essence of existential types. |