We mostly use data to store values, like this:
data Sex = Male | Female data Person = Person {name :: String, age :: Int, sex :: Sex} charlie :: Person charlie = Person "Charlie" 32 Male And now we have nice functions name age and sex to get data values with.
But, with GADTs and Rank2, we can do something cooler:
{-# LANGUAGE GADTs #-} {-# LANGUAGE Rank2Types #-} data Sex = Male | Female data Data a where Name :: Data String Age :: Data Int Sex :: Data Sex type Person = forall a. Data a -> a charlie :: Person charlie Name = "Charlie" charlie Age = 32 charlie Sex = Male So, this is pretty darned awesome. It provides us with a gloriously beautiful syntax for defining people, and makes slick use of GADTs.
But is this really any better? How is this represented at runtime? Is pattern-matching actually slower and/or bigger in representation than the data?
lt;dr: How fast is pattern matching compared to data lookup?
32, they will be re-evaluated each time. (Or you or the compiler floats it out of the function into a closure, and then you just reinvented storing data as data, with extra overhead to access it.)(->)representation is that updating fields leaks space and lookup gets slower after each update.