kenbot / goggles

Pleasant, yet principled Scala optics DSL
MIT License
196 stars 7 forks source link

Can types be obtained from the outer expression? #6

Closed kenbot closed 7 years ago

kenbot commented 7 years ago

Currently, "lens" expressions have to have an interpolated lens in the first position, because otherwise the types can't be inferred.

If we have, say:

val x: Lens[Monkey, Banana] = lens"..."

does that mean we can allow expressions that start with ?, .name, [i], or *, plugging in what we know about Monkeys and Bananas? Or does this fit into the official discouragement of accessing the surrounding scope?

kenbot commented 7 years ago

I don't think this ticket is as important as I thought it might be. What we really need to discover is the first type, which would enable lens mode expressions to flow typewise from left to right. However, if we know the type of the whole expression, we know the rightmost final type. To gain any inference value out of this, we would have to manually propagate influence from right to left. While I'm sure Haskell and Scala both do this, this seems like an enormously complex task. How would it handle types flowing from the left and right, where they disagree?

I don't want anything this complicated in the Goggles codebase, and in any case, #31 seems to address the motivation.