[Haskell] Proposal: Allow "\=" for field update in record update
syntax
Benjamin Franksen
benjamin.franksen at bessy.de
Thu Feb 24 14:39:15 EST 2005
On Thursday 24 February 2005 19:51, Keean Schupke wrote:
> Benjamin Franksen wrote:
> >I still wonder if your TH generated code can handle higher ranked field
> > types; i.e. can I write
> >
> >$(ttypelift [| data Record = Record {
> > field1 :: Int,
> > field2 :: (forall a. a-> a) } |] )
> >
> >or does ghc give me an error?
>
> Well at the moment this would give an error, but remember the
> list is heterogeneous, so you can just not give the list a type, and
> simply append the specific function... admitedly this is not as
> type-safe.
>
> hUpdateAtLabel field2 someFunction myRecord
That is an advantage of hLists as compared to normal records.
A disadvantage is that each field access needs to traverse the list. I wonder
if this isn't rather less efficient than the random access provided by normal
records.
> Of course if the type of the function is unknown until runtime, we have
> to use existential quantification.
>
> It might be possible to automatically wrap such types, but my feeling at
> the moment is that it is best left to the programmer.
Automatic wrapping is easy. What is not so easy and I think not even possible,
is automatic _un_wrapping, so that the wrapping isn't exposed at all to the
programmer.
I am not a type system guru, so can anyone enlighten me on why higher ranked
types are not allowed in instances? Is there a principle problem, or is it
just difficult to implement? Does this have to do with this "higher order
unification" that Haskell is alleged not to have?
Ben
More information about the Haskell
mailing list