0.15.0 won't completely infer types using VTA inside a record · Issue #4500 · purescript/purescript · GitHub
Skip to content

0.15.0 won't completely infer types using VTA inside a record #4500

Closed

Description

@jterbraak

Description

When using a value inside a record for which type depends on a type provided using the new VTA feature the compiler won't infer the type inside the record and instead leaves a forall. This then prevents other typeclasses like RowToList or Nub from working.

To Reproduce

module Example where

import Prelude

import Data.Reflectable (class Reflectable, reflectType)
import Type.Proxy (Proxy(..))

reflect :: forall @t v . Reflectable t v => v
reflect =
    reflectType ( Proxy @t )

use :: String
use =
    show { asdf : reflect @"asdf" }

Expected behavior

The code should compile and the value of use should be { asdf: "asdf" }

Additional context

The issue disappears when adding any other argument:

reflect :: forall @t v . Reflectable t v => Unit -> v
reflect _ =
    reflectType ( Proxy @t )

use :: String
use =
    show { asdf : reflect @"asdf" unit }

PureScript version

0.15.10

Activity

  1. changed the title [-]0.15.0 won't completly infer types using VTA inside a record[/-] [+]0.15.0 won't completely infer types using VTA inside a record[/+] on Aug 8, 2023
  2. JordanMartinez commented on Aug 8, 2023

    @JordanMartinez
    Contributor

    Posting the above code in Try PS: https://try.purescript.org/?code=FAWw9gJgrgNgpgAgLIEMCWA7BB3AFnAJzmGDRAAcwCAXBABSJigmNIqtoBEVqUA6AEpwAZvADGvAEbwEACjEwUAZyUIhouBJTS4AGgRENEgCoBPcnACUbSjQRmLfBmAAepuc7ey%2BfS9eCG4rQAXMEIwlQoMDAIAAK0AG4IfGoiQdoyiQgAvAB8CAkBaZq02cAIFQbFJuaIsvQEru7xCP5QSoihCADK1ASYAObA7YhllQhKuGDYCADeCMoQwghhgSVxAESLwhsIAL4kQA

    Error is:

    No type class instance was found for
    
        Prim.Row.Nub ( asdf :: forall v. Reflectable "asdf" v => v
                     )
                     ( asdf :: forall v. Reflectable "asdf" v => v
                     )
    
    
    while solving type class constraint
    
      Data.Show.Show { asdf :: forall (v :: Type). Reflectable @Symbol "asdf" v => v
                     }
    
    while applying a function show
      of type Show t0 => t0 -> String
      to argument { asdf: reflect
                  }
    while checking that expression show { asdf: reflect
                                        }
      has type String
    in value declaration use
    
    where t0 is an unknown type
    
  3. purefunctor commented on Aug 8, 2023

    @purefunctor
    Member

    #4376 introduced a typing rule for inferring property values inside of records:

    The propertyShouldInstantiate function has been used for a while now but I don't exactly recall why it's there. Adding a special case for VisibleTypeApp should do the trick provided that the term being applied satisfies propertyShouldInstantiate too.

  4. JordanMartinez commented on Aug 8, 2023

    @JordanMartinez
    Contributor

    That fixes it. PR incoming.

  5. natefaubion commented on Aug 8, 2023

    @natefaubion
    Contributor

    Isn't this #4380 rearing it's head again? I think it's fine to special case VisibleTypeApp for now, but I still think we should just remove this rule.

  6. JordanMartinez commented on Aug 8, 2023

    @JordanMartinez
    Contributor

    I agree, but that's a breaking change, right?

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions