Changes between Version 2 and Version 3 of Commentary/Compiler/DeriveFunctor


Ignore:
Timestamp:
Jul 2, 2015 6:13:53 PM (5 years ago)
Author:
RyanGlScott
Comment:

Expound more on simple type variables

Legend:

Unmodified
Added
Removed
Modified
  • Commentary/Compiler/DeriveFunctor

    v2 v3  
    277277{{{#!hs
    278278data E a where
    279     E1 :: (a ~ Int) => a   -> E1 a
    280     E2 ::              Int -> E1 Int
    281     E3 :: (b ~ Int) => b   -> E1 Int
    282     E4 :: (a ~ Int) => Int -> E1 a
     279    E1 :: (a ~ Int) => a   -> E a
     280    E2 ::              Int -> E Int
     281    E3 :: (b ~ Int) => b   -> E Int
     282    E4 :: (a ~ Int) => Int -> E a
    283283}}}
    284284
     
    307307For all we know, it may be that {{{a ~ Int => Mystery a}}}. Does this mean that the {{{Int}}} argument in {{{UC}}} should be folded over?
    308308
    309 To avoid these thorny edge cases, we only consider constructor arguments whose types are ''syntactically'' equivalent to the last type parameter. In the above {{{E}}} example, only {{{E1}}} fits the bill, so the derived {{{Foldable}}} instance should actually be:
     309To avoid these thorny edge cases, we only consider constructor arguments (1) whose types are ''syntactically'' equivalent to the last type parameter and (2) in cases when the last type parameter is a ''simple'' type variable. In the above {{{E}}} example, only {{{E1}}} fits the bill, so the derived {{{Foldable}}} instance should actually be:
    310310
    311311{{{#!hs
     
    322322}}}
    323323
     324To expound more on the meaning of criterion (2), we want not only to avoid cases like {{{E2 :: Int -> E Int}}}, but also something like this:
     325
     326{{{#!hs
     327data HigherKinded f a where
     328    HigherKinded :: f a -> HigherKinded f (f a)
     329}}}
     330
     331In this example, the last type variable is instantiated with {{{f a}}}, which contains one type variable {{{f}}} applied to another type variable {{{a}}}. We would ''not'' fold over the argument of type {{{f a}}} in this case, because the last type variable should be ''simple'', i.e., contain only a single variable without any application.
     332
    324333For the original discussion on this proposal, see [https://ghc.haskell.org/trac/ghc/ticket/10447 #10447].