Changes between Version 1 and Version 2 of TypeFunctions/TotalFamilies

Apr 6, 2008 9:31:19 AM (8 years ago)



  • TypeFunctions/TotalFamilies

    v1 v2  
    55To guarantee the termination and completeness of the solving of equality constraints, we need to impose rather draconian restrictions on the instances of type synonym families.  More specifically, to achieve both termination and completeness, we need the ''Strong Termination Condition'' and if we settle for termination alone (accepting to be incomplete for some rather exotic programs), we need the ''Relaxed (Termination) Condition'' as defined in [ Type Checking with Open Type Functions].  The ''Strong Termination Condition'' corresponds closely to the conditions imposed on functional dependencies.  The ''Relaxed Condition'' is somewhat more liberal, but still does not permit, for example, nested applications of type families in the right-hand side of a `type instance`.  For many practically attractive uses of type families, where the the system is actually terminating, this is still to restrictive.
    7 === An example ===
     7=== Two examples ===
    1010data Z; data S a;
     12-- meets the Strong Termination Condition
    1213type family x :+ y
    1314type instance Z   :+ y = y
    1415type instance S x :+ y = S (x :+ y)
     17-- meets only the Relaxed Condition
    1618type family x :* y
    1719type instance Z     :* y = Z
    1820type instance (S x) :* y = x :* y :+ y
    20 The family `(:+)` meets the ''Relaxed Condition'', but not the ''Strong Termination Condition''.  However, `(:*)` meets not even the ''Relaxed Condition''.
     22The family `(:+)` meets the ''Relaxed Condition'', but not the ''Strong Termination Condition''.  However, `(:*)` meets not even the ''Relaxed Condition''.  Nevertheless, we would expect that families defined by structural recursion should not compromise termination.  Another somewhat irritating aspect of this example is that we would like these definitions to be closed, but they are open in their present form.
     24We might want to define equality on types as
     26data TFalse; data TTrue;
     28type family TypeEq s t
     29type instance TypeEq s s = TTrue
     30type instance TypeEq s t = FFalse  -- matches only if the previous instance does not
     32Unfortunately, the two instances are overlapping and there is no means by which we can disambiguate the overlap by using the same textual ordering as that which we are used to from value-level functions.