You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
0.15.0 won't completely infer types using VTA inside a record #4500
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 }
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
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
-- Infer the type of a value when used as a record field.
inferWithinRecord
:: ( MonadSupplym
, MonadStateCheckStatem
, MonadErrorMultipleErrorsm
, MonadWriterMultipleErrorsm
)
=>Expr
->m (Expr, SourceType)
inferWithinRecord e =do
TypedValue' _ v t <- infer e
if propertyShouldInstantiate e
then instantiatePolyTypeWithUnknowns v t
elsepure (v, t)
--|
-- Determines if a value's type needs to be monomorphized when
-- used inside of a record.
propertyShouldInstantiate::Expr->Bool
propertyShouldInstantiate =\case
Var{} ->True
Constructor{} ->True
PositionedValue _ _ e -> propertyShouldInstantiate e
_ ->False
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.
Activity
[-]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[/+]JordanMartinez commentedon Aug 8, 2023
Posting the above code in Try PS: https://try.purescript.org/?code=FAWw9gJgrgNgpgAgLIEMCWA7BB3AFnAJzmGDRAAcwCAXBABSJigmNIqtoBEVqUA6AEpwAZvADGvAEbwEACjEwUAZyUIhouBJTS4AGgRENEgCoBPcnACUbSjQRmLfBmAAepuc7ey%2BfS9eCG4rQAXMEIwlQoMDAIAAK0AG4IfGoiQdoyiQgAvAB8CAkBaZq02cAIFQbFJuaIsvQEru7xCP5QSoihCADK1ASYAObA7YhllQhKuGDYCADeCMoQwghhgSVxAESLwhsIAL4kQA
Error is:
purefunctor commentedon Aug 8, 2023
#4376 introduced a typing rule for inferring property values inside of records:
purescript/src/Language/PureScript/TypeChecker/Types.hs
Lines 549 to 573 in 4afea2f
The
propertyShouldInstantiatefunction has been used for a while now but I don't exactly recall why it's there. Adding a special case forVisibleTypeAppshould do the trick provided that the term being applied satisfiespropertyShouldInstantiatetoo.JordanMartinez commentedon Aug 8, 2023
That fixes it. PR incoming.
natefaubion commentedon Aug 8, 2023
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.
JordanMartinez commentedon Aug 8, 2023
I agree, but that's a breaking change, right?