Data families vs Injective type families

前端 未结 3 731
南旧
南旧 2020-12-13 15:00

Now that we have injective type families, is there any remaining use case for using data families over type families?

Looking at past StackOverflow questions about d

3条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-13 15:22

    The answer by Reid Barton explains the distinction between my two examples perfectly. It has reminded me of something I read in Richard Eisenberg's thesis about adding dependent types to Haskell and I thought that since the heart of this question is injectivity and generativity, it would be worth mentioning how DependentHaskell will deal with this (when it eventually gets implemented, and if the quantifiers proposed now are the ones eventually implemented).

    What follows is based on pages 56 and 57 (4.3.4 Matchability) of the aforementioned thesis:

    Definition (Generativity). If f and g are generative, then f a ~ g b implies f ~ g

    Definition (Injectivity). If f is injective, then f a ~ f b implies a ~ b

    Definition (Matchability). A function f is matchable iff it is generative and injective

    In Haskell as we know it now (8.0.1) the matchable (type-level) functions consist exactly of newtype, data, and data family type constructors. In the future, under DependentHaskell, one of the new quantifiers we will get will be '-> and this will be used to denote matchable functions. In other words, there will be a way to inform the compiler a type-level function is generative (which currently can only be done by making sure that function is a type constructor).

提交回复
热议问题