Skip to content

Warn about unusable instances when types are missing from exports #3394

Description

@garyb

Both @thomashoneyman and I have run into this - it can be very difficult to figure out why instance resolution is failing, so having a warning about it would save many hours of wasted time for the few people that encounter it!

The case we encountered it is creating an "app monad" that also has a parallel version as a newtype, and then forgetting to export the parallel version - the Parallel instance exists, but any attempts to resolve the Parallel constraint for the app monad outside of the defining module fails with a missing instance error.

Activity

  1. added this to the 1.0 milestone on Jun 28, 2018
  2. hdgarrood commented on Dec 17, 2018

    @hdgarrood
    Contributor

    I think I also ran into this while trying to put together a generic implementation of the Debug class in https://github.com/hdgarrood/purescript-debugged/, by exporting GenericDebug but forgetting to export GenericDebugArgs. Just to check, is this what you had in mind?

    module Main (Tuple(..), class Y, y) where
    
    data Tuple a b = Tuple a b
    
    class X a where
      x :: a
    
    instance xInt :: X Int where
      x = 0
    
    class Y a b where
      y :: Tuple a b
    
    instance yInt :: X a => Y a Int where
      y = Tuple x 1

    Then any attempt to write e.g. (y :: Tuple Int Int) in another module will give you

      No type class instance was found for class
        Main.X
      because the class was not in scope. Perhaps it was not exported.
    while solving type class constraint
      Main.X Int
    

    Have we considered having a non-exported type or class appear in an instance for an exported class be an error? It seems consistent with the existing behaviour of requiring members of an exported class to be exported, and I don't think it ever makes sense to export a class but make one or more of its instances unusable by not exporting things they reference.

  3. garyb commented on Dec 17, 2018

    @garyb
    MemberAuthor

    Have we considered having a non-exported type or class appear in an instance for an exported class be an error?

    Yeah, that's essentially how I'd like to fix this.

    edit: Oh, I see what you mean - I said warning, but it could be an error immediately. Yeah, that works too!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions