product not working with nesting
yaitskov opened this issue · 2 comments
Hi,
Tried to define router for a composite type:
data Route = R1 Int (Array Int)
-- or
data Route = R1 Int (Tuple Int Int)
Following parsers cannot pass the type checker
(product (int segment) (many (int segment)))
-- or
(product
(int segment)
(product (int segment) (int segment)))
No type class instance was found for
Routing.Duplex.Generic.GRouteDuplexCtr (t3 Int)
(Argument (Array Int))
The following instance partially overlaps the above constraint, which means the rest of its instance chain will not be considered:
Routing.Duplex.Generic.gRouteArgument
The instance head contains unknown type variables. Consider adding a type annotation.
while applying a function product
of type GRouteDuplexCtr t0 t1 => RouteDuplex t2 t2 -> RouteDuplex t0 t0 -> RouteDuplex (Product ... t1) (Product ... t1)
to argument int segment
while inferring the type of product (int segment)
in value declaration routeCodec
Could not match type
Product (Argument Int)
with type
Argument
while trying to match type Product (Argument Int) (Argument Int)
with type Argument (Tuple Int Int)
while solving type class constraint
Routing.Duplex.Generic.GRouteDuplexCtr t2
(Product (Argument Int) (Argument (Tuple Int Int)))
many
uses return polymorphism and lets you build things of different types:
purescript-routing-duplex/src/Routing/Duplex.purs
Lines 218 to 223 in 13702d4
Unfortunately, inference is failing here, but it can be mitigated with a type annotation.
https://try.purescript.org/?code=LYewJgrgNgpgBAWQIYEsB2cDuALGAnGAKEJWAAcQ8AXOABQKgjHmxTHQHM4AKbgegCUA4qQrU4AESRUkAOgDiMNPhQBjWQCUYZEuUo0NICFU6yJEMrAAeusQaMm0HMxesKlK1bf1xDx0%2BaWMFbuynhqsgDKAJ5oMjaEYNJIcAAqMADONAC8aZk0AJJxPACCeHhI0XBFVMKJKgBu8OhZSGiq8IphanlZcAD6xFT5cABco74OMIHWAOS9VITDfbkZEMCEcHAA3nAAROlZexNkeOAQqjTc6DQZMBzASrU8wG1V18V3D08CYxN%2BwxmwXm3DKFSq-SEmzgAF8gA
I wonder if there's something we can add to the instance chain to help with this inference. Otherwise this would be a good use case for type applications.
Thanks. Explicit type annotation helps.
I found issue about that bug in compiler
purescript/purescript#4338