title: How to update a Data attribute defined with Maybe
body: <p>I'm playing with Haskell using <a href="https://hackage.haskell.org/package/cursor" rel="nofollow noreferrer">https://hackage.haskell.org/package/cursor</a> library. I have this data definition:</p>
  <pre><code>data TuidoState =
    TuidoState  { tuidoStateEntries :: Maybe (NonEmptyCursor Entry) }
  </code></pre>
  <p>And I have this function:</p>
  <pre><code>buildNewItem :: TuidoState -&gt; TuidoState
  buildNewItem s =
    let nextID = 10 -- TODO update here to function to return ID
        headerTitle = &quot;Test new item&quot;
        newEntry = Entry { entryHeader= Header { headerTitle= headerTitle }
                                , entryBody= Just (Body { bodyTitle= headerTitle })
                                , entryTags= [Tag {tagName= headerTitle}]
                                }
        actualEntries = (tuidoStateEntries s)
        ne = NE.nonEmpty [newEntry]
    in
      case actualEntries of
        Nothing -&gt;
          s { tuidoStateEntries = Just(makeNonEmptyCursor ne)  }
        Just value -&gt; s { tuidoStateEntries = Just(value) } -- possible here I will want to just add the new Entry to the existing list
  </code></pre>
  <p>But, I cannot understand the error:</p>
  <pre><code> • Couldn't match expected type ‘NE.NonEmpty Entry’
                    with actual type ‘Maybe (NE.NonEmpty Entry)’
      • In the first argument of ‘makeNonEmptyCursor’, namely ‘ne’
        In the first argument of ‘Just’, namely ‘(makeNonEmptyCursor ne)’
        In the ‘tuidoStateEntries’ field of a record
      |
  327 |         s { tuidoStateEntries = Just(makeNonEmptyCursor ne)  }
  </code></pre>
  <p>Could someone help me with it?</p>