Records in Haskell

Greg Weber greg at gregweber.info
Wed Jan 11 10:35:45 CET 2012


I added your relevant previous notes to the wiki page. I have no idea if
what you said about type inference is right or wrong. I don't think that
record fields can be called scope resolution in a normal sense - the scope
is guaranteed to resolve without conflict (unless the user incorrectly
types the field name).

We do need those very familiar with the GHC internals to weigh in with any
implementation objections.

On Tue, Jan 10, 2012 at 11:42 PM, Isaac Dupree <
ml at isaac.cedarswampstudios.org> wrote:

> On 01/10/2012 05:06 AM, Greg Weber wrote:
>
>> Some of your comments seem to not fully recognize the name-spacing (plus
>> simple type resolution) aspect of this proposal that I probably didn't
>> explain well enough. Or maybe I don't understand your comments.
>>
>> For record.field, field is under the record's namespace. A namespace (from
>> a module or under the new system a record), cannot export conflicting
>> names, and there this system prevents the importer from every having a
>> conflict with a record field name because the field is still under the
>> record's namespace when imported. The type system must resolve the type of
>> the record, and generally the field cannot contribute to this effort.
>>
>
> (I have only used Haskell for several years, not implemented Haskell
> several times; apologies for my amateurish understanding of the type
> system.)
>
> So
> Type inference proceeds assuming that "record.field" is something
> equivalent to "undefined record" (using "undefined" as a function type),
> and the program is only correct if the type of "record" resolves to a
> concrete type? I don't know if "concrete type" is at all the right
> terminology; I mean a type-variable doesn't count (whether
> class-constrained, "Num a => a", or not, "a", or even "m Int" is not
> concrete).  Is "forall a. Maybe a" okay (if Maybe were a record)? "forall
> a. Num a => Maybe a"?  I'm guessing "yes".
> Does it get harder in the presence of the type-system extensions?
> "(a ~ SomeRecord) => a": presumably that works with record syntax?  Can
> the compiler always figure out whether or not it can find a type-variable's
> concrete type?
>
> My concept of Haskell is that (except for Template Haskell), scope
> resolution happens before type inference happens, no exceptions.  So you're
> deliberately breaking that pattern.  Right?
>
> Does this order of stages (regular scope selection, then type inference,
> then record scope) make as high a fraction of code work as Frege's
> left-to-right model (which I am guessing interleaves type inference and
> record scope selection as it proceeds left-to-right through the program)?
>
> Correct me if I got something wrong,
>
> -Isaac
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/glasgow-haskell-users/attachments/20120111/ff8a8baa/attachment.htm>


More information about the Glasgow-haskell-users mailing list