Changes between Version 18 and Version 19 of Records/OverloadedRecordFields/Plan


Ignore:
Timestamp:
Jul 4, 2013 6:53:41 PM (2 years ago)
Author:
adamgundry
Comment:

Trouble in paradise

Legend:

Unmodified
Added
Removed
Modified
  • Records/OverloadedRecordFields/Plan

    v18 v19  
    190190
    191191
     192=== Trouble in paradise ===
     193
     194[http://www.haskell.org/pipermail/glasgow-haskell-users/2013-July/024064.html Edward Kmett points out] that the current story falls short in one important respect: composition of polymorphic record fields leads to ambiguity errors, as the intermediate type cannot be determined. For example, suppose
     195
     196{{{
     197foo :: Has b "foo" c => b -> c
     198bar :: Has a "bar" b => a -> b
     199}}}
     200
     201then
     202
     203{{{
     204foo . bar :: (Has a "bar" b, Has b "foo" c) => a -> c
     205}}}
     206
     207and `b` is an ambiguous type variable.
     208
     209We could work around this by adding a functional dependency
     210
     211{{{
     212class Has r (f :: Symbol) t | r f -> t where
     213  getFld :: r -> t
     214}}}
     215
     216or using a type family
     217
     218{{{
     219class Has r (f :: Symbol) where
     220  type GetResult r f :: *
     221  getFld :: r -> GetResult r f
     222}}}
     223
     224but either of these options prevents the integration with lenses discussed above, and we lose support for universally quantified fields (though they are dubious anyway). Pick your poison.
     225
     226
    192227=== User-defined `Has` instances ===
    193228