Changing the warning message for UnusedTypeVar

The following code snippet gives me an unused type var warning:

module ExistentialQualification2 where

import Prelude
import Data.Newtype (class Newtype)
import Data.Typeclass (tnil, using, (@>))
import Effect (Effect)
import Effect.Class.Console (log)

newtype ShowMe a
  = ShowMe (a -> String)

derive instance newtypeShowMe :: Newtype (ShowMe a) _

existentialQualification2 :: forall x. Effect Unit
existentialQualification2 = do
  let
    myShow =
      ShowMe (\(i :: x -> x) -> "Yo! Neda!")
        @> ShowMe (\i -> "Not " <> (show :: Boolean -> String) (not i))
        @> tnil
  log $ using myShow (\(x :: x) -> x)
  log $ using myShow false

You can see it here in the IDE.

And the specific warning:

But the code won’t compile without the type variable. The output, when compiled, works as expected:

Yo! Neda!
Not true

I’m wondering if there is a way to suppress and/or change the warning when the type variable is used? Or is there something I’m missing and is it possible not to use the type variable?

I can’t find Data.Typeclass to try this myself, but could it work to do

module ExistentialQualification2 where

import Prelude
import Data.Newtype (class Newtype)
import Data.Typeclass (tnil, using, (@>))
import Effect (Effect)
import Effect.Class.Console (log)

newtype ShowMe a
  = ShowMe (a -> String)

derive instance newtypeShowMe :: Newtype (ShowMe a) _

existentialQualification2 :: Effect Unit
existentialQualification2 = do
  let
    myShow =
      ShowMe (\(i :: forall x. x -> x) -> "Yo! Neda!")
        @> ShowMe (\i -> "Not " <> (show :: Boolean -> String) (not i))
        @> tnil
  log $ using myShow identity
  log $ using myShow false

I don’t think that has a different meaning in this case, but I could be mistaken about that.

The meaning is slightly different. If the type of existentialQualification2 is forall x. Effect Unit, then you’re letting the caller say what x is. For @ntwilson’s version, you’re binding x inside ShowMe, which means that a) the caller doesn’t know or care about it at all, and b) you could potentially instantiate x to more than one type inside the body of existentialQualification2.

The difference might become clearer if/when PureScript gets explicit type applications, but we don’t have those yet.

By the way, I think you mean “existential quantification” rather than “qualification”.

Hey! Apologies, the library is not in the package set yet (the PR is in review) - it is https://github.com/mikesol/sytc.

@mikesol I think you mean https://github.com/mikesol/purescript-sytc.

1 Like