Skip to content
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

Eval plugin reports "Ambiguous type variable" where ghci does not. #1591

Closed
fmehta opened this issue Mar 18, 2021 · 4 comments · Fixed by #1596
Closed

Eval plugin reports "Ambiguous type variable" where ghci does not. #1591

fmehta opened this issue Mar 18, 2021 · 4 comments · Fixed by #1596
Labels
can-workaround component: hls-eval-plugin type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc..

Comments

@fmehta
Copy link
Contributor

fmehta commented Mar 18, 2021

Which lsp-client do you use:
VS Code

Steps to reproduce

Type -- >>> head []in the editor and click on Evaluate...

Expected behaviour

Output:
*** Exception: Prelude.head: empty list
as in ghci.

Actual behaviour

Output:

-- Ambiguous type variable ‘f0’ 
-- prevents the constraint ‘(Show f0)’ from being solved.
-- Probable fix: use a type annotation to specify what ‘f0’ should be.
-- These potential instances exist:
--   instance Show a => Show (ZipList a)
--     -- Defined in ‘Control.Applicative’
--   instance Show NestedAtomically
--     -- Defined in ‘Control.Exception.Base’
--   instance Show NoMethodError -- Defined in ‘Control.Exception.Base’
--   ...plus 215 others
--   (use -fprint-potential-instances to see them all)

Workaround

Specifying a concrete type, such as -- >>> head ([]::[Int]) does not result in this error, but is not pretty.

@jneira jneira added component: hls-eval-plugin type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc.. labels Mar 18, 2021
@berberman
Copy link
Collaborator

GHCi enables ExtendedDefaultRules by default, so head [] can be type-checked. You could enable this language extension to get the similar behaviour. It wouldn't be hard to let eval plugin enable this by default as well, so PRs are welcome!

@July541
Copy link
Collaborator

July541 commented Mar 30, 2021

I built the master branch without ExtendedDefaultRelus, but -- >>> head [] print *** Exception: Prelude.head: empty list correctly as we often met. I checked the log file and found nothing different between the official version and my own build.

Reproduce procedure:

  1. run cabal build
  2. copy from dist-newstyle executable file path to VSCode setting file Haskell: Server Executable Path

@berberman
Copy link
Collaborator

Actually, head [] in ghci can be typechecked without ExtendedDefaultRelus. It's kind of subtle -- in this case, the type of head [] is unified to IO a, resulting in a new interactive binding, instead of printing an expression. Thus, there is no Show constraint need to be satisfied, where no "ambiguous type variable" occurs.

#1603 made eval plugin behave like ghci, so it works in master now, but didn't work as this issue was created. However, ExtendedDefaultRelus is still important in other cases, and we'd better change the example of this issue to reverse [].

@Ailrun
Copy link
Member

Ailrun commented May 7, 2021

Simpler case requires ExtendedDefaultRules:

-- >>> []

@mergify mergify bot closed this as completed in #1596 Jun 23, 2021
mergify bot added a commit that referenced this issue Jun 23, 2021
#1596)

* Enable ExtendedDefaultRules for expressions in eval plugin (#1591)

* Add tests for fix#1591

* Add fix for #1954

* Remove dependency on xopt_set_unlessExplSpec.
Reason: It was breaking GHC 8.6.2 tests.

* Remove unnecessary comment.

Co-authored-by: Potato Hatsue <berberman@yandex.com>

Co-authored-by: Javier Neira <atreyu.bbb@gmail.com>
Co-authored-by: Potato Hatsue <1793913507@qq.com>
Co-authored-by: Potato Hatsue <berberman@yandex.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
can-workaround component: hls-eval-plugin type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc..
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants