Skip to content

Unhelpful error with associated types #13

@noughtmare

Description

@noughtmare

In this stackoverflow question the asker presents this code:

{-# LANGUAGE TypeFamilies #-}

class Reproductive a where

  -- | A sequence of genetic information for an agent.
  type Strand a

  -- | Full set (both strands) of genetic information for an organism.
  type Genome a = (Strand a, Strand a)

But this produces the unhelpful error message (I was confused for a minute):

Assoc.hs:20:8: error:
    ‘Genome’ is not a (visible) associated type of class ‘Reproductive’
   |
20 |   type Genome a = (Strand a, Strand a)
   |        ^^^^^^

As a user I'm thinking that I'm defining an associated type, but this error message says that it expects the type to already be defined.

I now understand that you can easily solve this by writing a separate "kind signature" where the signature part can be omitted because it defaults to *:

{-# LANGUAGE TypeFamilies #-}

class Reproductive a where

  -- | A sequence of genetic information for an agent.
  type Strand a

  -- | Full set (both strands) of genetic information for an organism.
  type Genome a
  type Genome a = (Strand a, Strand a)

I think this warning can be improved, but I'm not sure how, yet.

Metadata

Metadata

Assignees

No one assigned

    Labels

    status:Composing error messageImproving the error message is under discussion and WIPtool:GHCFor error messages originating from GHCtype:error-messageThis issue focuses on improving a error messaging in Haskell Tools

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions