purescript-contrib / purescript-profunctor-lenses

Pure profunctor lenses
MIT License
144 stars 52 forks source link

_2 implemented in terms of `second` doesn't work too well #17

Closed garyb closed 8 years ago

garyb commented 8 years ago

Starting with:

type X = { page :: Tuple (Maybe String) Int }

_page :: LensP X (Tuple (Maybe String) Int)
_page = lens _.page (_ { page = _ })

Trying to use:

_page <<< _2

Results in:

  Could not match type

    Function (Star (Const _0) _0 _1)

  with type

    Object

But using the original definitions we had works fine:

_snd :: forall a b c. Lens (Tuple c a) (Tuple c b) a b
_snd = lens snd (\(Tuple c _) b -> Tuple c b)

_page <<< _snd

@paf31 I guess this is more a bug for the typechecker than for this library, should I open something on the compiler repo?

garyb commented 8 years ago

Bizzarely, _page <<< second works fine also.

paf31 commented 8 years ago

That's odd. Don't the two versions have the same types?

Sent from my iPhone

On Dec 8, 2015, at 1:43 PM, Gary Burgess notifications@github.com wrote:

Starting with:

type X = { page :: Tuple (Maybe String) Int }

_page :: LensP X (Tuple (Maybe String) Int) page = lens .page ( { page = }) Trying to use:

_page <<< _2 Results in:

Could not match type

Function (Star (Const _0) _0 _1)

with type

Object

But using the original definitions we had works fine:

_snd :: forall a b c. Lens (Tuple c a) (Tuple c b) a b snd = lens snd ((Tuple c ) b -> Tuple c b)

_page <<< _snd @paf31 I guess this is more a bug for the typechecker than for this library, should I open something on the compiler repo?

— Reply to this email directly or view it on GitHub.

garyb commented 8 years ago

_2 and _snd have exactly the same type, yeah.

paf31 commented 8 years ago

Sanity check - this is the _2 from this library, not the van Laarhoven one?

Sent from my iPhone

On Dec 8, 2015, at 1:54 PM, Gary Burgess notifications@github.com wrote:

_2 and _snd have exactly the same type, yeah.

— Reply to this email directly or view it on GitHub.

paf31 commented 8 years ago

Does it work if you define the alias in a where block?

Sent from my iPhone

On Dec 8, 2015, at 1:54 PM, Gary Burgess notifications@github.com wrote:

_2 and _snd have exactly the same type, yeah.

— Reply to this email directly or view it on GitHub.

garyb commented 8 years ago

_2 is definitely imported from Data.Lens rather than Optic. It does work if I define it in a where:

  where
  _22 :: forall a b c. Lens (Tuple c a) (Tuple c b) a b
  _22 = second
garyb commented 8 years ago

It also works if I don't define it in a where, but in the same module :sob:

Something rather strange going on here...

garyb commented 8 years ago

Ok, there's something really weird going on in fact! I didn't notice, but I'd used _2 elsewhere in the module succesfully. However, if I remove the import of _2 entirely and comment out the other usage, this:

wtf :: Maybe Unit
wtf = do
  x <- pure unit
  let tmp = review (_page <<< _2)
  pure unit

Raises the error, rather than the error it should raise: Unknown value _2.

Dropping the x <- ... line means we get the "unknown value" error. Extracting wtf into its own module also gives us the "unknown value" error rather than the type error. I'm trying to make a smaller test case...

garyb commented 8 years ago

lol: purescript/purescript#1697