Content-Length: 273067 | pFad | https://github.com/purescript/purescript/issues/4488

30 `WildcardInferredType` warning when using wildcards in a visible type application · Issue #4488 · purescript/purescript · GitHub
Skip to content

WildcardInferredType warning when using wildcards in a visible type application #4488

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
fsoikin opened this issue Jul 19, 2023 · 5 comments · Fixed by #4492
Closed

WildcardInferredType warning when using wildcards in a visible type application #4488

fsoikin opened this issue Jul 19, 2023 · 5 comments · Fixed by #4492

Comments

@fsoikin
Copy link
Contributor

fsoikin commented Jul 19, 2023

Description

Using wildcards in a visible type application produces a WildcardInferredType warning.

To Reproduce

f :: forall @a. a -> a
f = identity

x :: { x :: Int }
x = f @{ x :: _ } { x: 42 }

Compiler output:

Wildcard type definition has the inferred type

    Int

in value declaration x
PureScript(WildcardInferredType)

Expected behavior

There should be no warning.

PureScript version

0.15.10

@JordanMartinez
Copy link
Contributor

There's a related issue with type holes:

module Main where

import Prelude
import Effect (Effect)
import Effect.Console (log)

f :: forall @a. a -> a
f = identity

x :: { x :: Int }
x = f @{ x :: ?Help } { x: 42 }

main = log "Done"

produces:

  tests/TestCompiler.hs:140:18: 
  1) compiler, Passing examples, 'VTAsHole.purs' should compile and run without error
       Error found:
       in module Main
       at tests/purs/passing/VTAsHole.purs:11:15 - 11:20 (line 11, column 15 - line 11, column 20)
       
         Hole 'Help' has the inferred type
              
           Int
              
       
       in value declaration x
       
       See https://github.com/purescript/documentation/blob/master/errors/HoleInferredType.md for more information,
       or to contribute content related to this error.
       

  To rerun use: --match "/compiler/Passing examples/'VTAsHole.purs' should compile and run without error/"

Randomized with seed 194657359

How should this case be handled?

@rhendric
Copy link
Member

Holes are an explicit request for information; I think that behavior's correct.

@JordanMartinez
Copy link
Contributor

But aren't type applications a user-supplied piece of information?

AFAICT, wildcards are only allowed in VTAs as a means of skipping the next type variable because there's not an alternative syntax.

@rhendric
Copy link
Member

But aren't type applications a user-supplied piece of information?

Yes. Let me restate: a hole is the user asking the compiler for information. No program with a hole anywhere in the source should compile, because the hole doesn't say ‘I don't care’ like a wildcard does; it says ‘tell me what I should put here (instead of completing the compilation)’.

@JordanMartinez
Copy link
Contributor

I understand that. I'm asking, "Just because VTAs can be used to do that, should they?"

🤔 Perhaps my understanding of VTAs' purpose is too limited. I guess there's really no difference between these two mechanisms for instructing the compiler what the type with which to unify a is aside from which mechanism one uses:

f :: forall @a. a -> a
f = identity

bar = f @Int

baz = (f :: Int -> _)

They are different in that

  • VTAs specify one part that may or may not affect the expression's type whereas type annotations can affect part (e.g. f :: Int -> _) or all (e.g. f :: Int -> Int) of the expression's type
  • VTAs are order-dependent whereas type annotations are not
  • VTAs are opt-in whereas type annotations are not.
  • VTAs are less verbose than type annotations

If I'm arguing that VTAs should not allow type holes, then you could counter by asking, "Why can type annotations have them? If we want to be consistent, we should remove type holes from type annotations as well."

Well... all that to say... It feels weird to me to allow them here, but I can't disagree with them being there anymore based on the previous paragraph.

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

Successfully merging a pull request may close this issue.

3 participants








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://github.com/purescript/purescript/issues/4488

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy