purescript-contrib / purescript-profunctor-lenses

Pure profunctor lenses
MIT License
144 stars 52 forks source link

Strange error with Strong/Forget #110

Closed CGenie closed 4 years ago

CGenie commented 4 years ago

Hello, I'm using profunctor-lenses v 6.2.0 with purescript 0.13.6. I'm getting the following error:

Error found:
in module Gargantext.Components.Nodes.Annuaire.User.Contacts
at src/Gargantext/Components/Nodes/Annuaire/User/Contacts.purs:149:22 - 149:72 (line 149, column 22 - line 149, column 72)

  Could not match constrained type

    Strong p0 => p0 String String -> p0 HyperdataUser HyperdataUser

  with type

    Forget String String t1 -> Forget String HyperdataUser t2

while trying to match type Strong p0 => p0 String String -> p0 HyperdataUser HyperdataUser
  with type Forget String String t1 -> Forget String HyperdataUser t2
while checking that expression (hooksComponent "G.C.N.A.U.C.contactInfoItem") cpt
  has type Component
             ( hyperdata :: HyperdataUser
             , lens :: forall p. Strong p => ... -> ...
             , onUpdateHyperdata :: HyperdataUser -> Effect Unit
             )
in value declaration contactInfoItemCpt

where p0 is a rigid type variable
        bound at (line 52, column 21 - line 52, column 58)
      t1 is an unknown type
      t2 is an unknown type

for the following code: https://gitlab.iscpif.fr/gargantext/purescript-gargantext/blob/dev-user-page-lens-test/src/Gargantext/Components/Nodes/Annuaire/User/Contacts.purs#L137-154 The lens are defined here: https://gitlab.iscpif.fr/gargantext/purescript-gargantext/blob/dev-user-page-lens-test/src/Gargantext/Components/Nodes/Annuaire/User/Contacts/Types.purs#L210-228

What is funnier, when I don't specify the types:

contactInfoItem :: Record ContactInfoItemProps -> R.Element
contactInfoItemCpt :: R.Component ContactInfoItemProps

the code compiles fine. However, it will fail at compiling when I use both the view and set functions (set is currently commented out here: https://gitlab.iscpif.fr/gargantext/purescript-gargantext/blob/dev-user-page-lens-test/src/Gargantext/Components/Nodes/Annuaire/User/Contacts.purs#L179-180) The error is then:

Error found:
in module Gargantext.Components.Nodes.Annuaire.User.Contacts
at src/Gargantext/Components/Nodes/Annuaire/User/Contacts.purs:153:27 - 153:31 (line 153, column 27 - line 153, column 31)

  Could not match type

    Function

  with type

    Forget t0

while trying to match type Function t4
  with type Forget t0 t0
while checking that expression lens
  has type Forget t0 t0 t1 -> Forget t0 t2 t3
in value declaration contactInfoItemCpt

I tried to debug this somehow and created simple code with view and set and created a stub func which is somewhat similar to contactInfoItemCpt from above: https://gitlab.iscpif.fr/gargantext/purescript-gargantext/blob/dev-user-page-lens-test/src/LensTest.purs The function func can be called like this:

func defaultT $ _s <<< _last

This works fine however and I'm really lost here.

Any help appreciated :)

garyb commented 4 years ago

It looks like you're trying to put it into (or take it from) a record? There are some issues with that, which is why it worked fine in your test function but not in the real situation.

The usual way of handling it is to use the concrete versions of the optic instead, so ALens instead of Lens, APrism' instead of Prism', etc.

You can put your normal non-concretely-defined optics into a record typed with these, but when you pull them out you'll need to use cloneLens or clonePrism etc. before you can work with it as normal again.

CGenie commented 4 years ago

OK indeed this fixed the issue, thank you!