0

I have a data similar to, but a bit more nested and of course named differently:

data AppModel = AppModel
 { _foo :: Maybe String
 } deriving (Eq, Show)

I would like to pass it to the Monomer textField

textField :: WidgetEvent e => ALens' s Text -> WidgetNode s e
textField field = textField_ field def

I found it can be lensed with _Just prism, but when appling it in the way it was suggested https://stackoverflow.com/a/44624359/11684473

textField $ foo . _Just . packed

It fails with:

No instance for (Applicative (Control.Lens.Internal.Context.Pretext (->) Text Text)) arising from a use of ‘_Just’

**What will be the proper way to expose the maybe value in the textField?

majkrzak
  • 1,332
  • 3
  • 14
  • 30
  • 1
    Lenses and prisms are similar but different things. If you combine a lens with a prism, you end up with a traversal, the "least common ancestor" of the two. Think about it this way: what is your lens supposed to do when then `foo` value is `Nothing`? In other words, say you used it to extract the `String` value (like, `myAppModel ^. foo . _Just`) -- what `String` do you get when `foo` is `Nothing`? – DDub Feb 06 '23 at 02:26

0 Answers0