Skip to content

Discrepancy between instance declarations: type families vs. type classes #31

Open
@ghost

Description

There is a discrepancy between the way instances of type families and type classes are represented in HSE.

data Decl l
    ...

So far so good.

    ...
    | TypeInsDecl  l     (Type l) ...
    | DataInsDecl  l ... (Type l) ...
    | GDataInsDecl l ... (Type l) ...
    ...

This is a very broad type, which is not too type-safe, but it might be handy for some applications to have an instance head to be presented like this.

    ...
    | InstDecl     l (Maybe (Context l)) (InstHead l) ...
    | DerivDecl    l (Maybe (Context l)) (InstHead l)
    ...

This is a much narrower type, but at least we can be sure that the type will be like C t1 .. tn, which is helpful in certain situations. However, it's currently too narrow and it causes problems (see #9), so it should perhaps include (Maybe [TyVarBind l]). It might even be useful to absorb these two fields into the InstHead data type.

For Language.Haskell.Exts.Syntax it's worse.

data Decl
    ...
    | TypeInsDecl  SrcLoc     Type ...
    | DataInsDecl  SrcLoc ... Type ...
    | GDataInsDecl SrcLoc ... Type ...
    ...

For type families, nothing really changes.

    ...
    | InstDecl     SrcLoc Context QName [Type] ...
    | DerivDecl    SrcLoc Context QName [Type]
    ...

For type classes, there isn't even an InstHead data type.

I suggest that all these cases should be turned into one encoding, be it Types or InstHeads. In my opinion, InstHead is the most HSE-ish approach here.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions