4 ms·
Haskell is getting row polymorphism[1] for records (going under the name OverloadedRecordFields) in the next release. The new language extension will also play
by tikhonj 12y ago
Haskell is getting row polymorphism[1] for records (going under the name OverloadedRecordFields) in the next release. The new language extension will also play well with lenses, making records even more versatile.
However, we're still not getting special syntax for field access, so it'll be function application (g f) instead of a dot (f.g). This isn't a major drawback, but it means that a field g has to be in scope for this to work at all.
Fundamentally, it seems exactly the same approach could be used to give Haskell polymorphic variants. They're not part of this extension, but I wouldn't be surprised to see them in the near future.
Haskell is also getting a much better (ie not crippled) module system soon, in the form of Backpack[2]. However, I'm not sure when this is actually going to be released—I don't think it's in the upcoming version.
[1]: http://www.well-typed.com/blog/84/ http://www.well-typed.com/blog/84/
[2]: http://plv.mpi-sws.org/backpack/ http://plv.mpi-sws.org/backpack/
- freyrs3 12y agoFrom the talks I've seen Gundry usually tends to qualify comments about OverloadedRecordFields by saying it's not traditional row polymorphism ( i.e. Record { name :: String | r }) ). It doesn't allow row extension or row restriction as first-class constructs in the type system. Although we can build these things as secondary features on top of the language as many libraries currently do though.
- jordwalke 12y agoWhen you say it's not first class, you mean that it can only be inferred?
- freyrs3 12y agoInference is orthogonal, I mean that a records don't have a distinct type in the type system. So structurally the following types are the same in Haskell, except one elaborates out a selector function. data Foo = Foo { name :: String } data Foo = Foo String What row polymorphism does is give use first-class record types that give us a measure of structural typing so that records with the "same" fields can be used in the same type and "larger" records can inhabit "smaller" types if the fields subsume. So we can write down a function like: foo :: forall r. { a :: Int, b :: Int | r } -> Int foo x = x.a + x.b The current proposal doesn't give us this. But we can still simulate it even if it isn't in the language.