<div dir="ltr"><div><span style="font-size:12.8px">Identity </span></div><div><br></div><div><a href="http://hackage.haskell.org/package/mtl-2.2.1/docs/Control-Monad-Identity.html">http://hackage.haskell.org/package/mtl-2.2.1/docs/Control-Monad-Identity.html<span style="font-size:12.8px"><br></span></a></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">may work: </span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px"> data A m = A {</span><br style="font-size:12.8px"><span style="font-size:12.8px"> a1 :: m B</span><br style="font-size:12.8px"><span style="font-size:12.8px"> }</span><br style="font-size:12.8px"><span style="font-size:12.8px"> data B m = B {</span><br style="font-size:12.8px"><span style="font-size:12.8px"> b1 :: m C</span><br style="font-size:12.8px"><span style="font-size:12.8px"> ... }</span><br></div><div><br></div><div>m: Maybe or Identity</div><div><br></div><div>- any good?</div><div><br></div><br></div><div class="gmail_extra"><br><div class="gmail_quote">On 6 July 2017 at 11:12, Baa <span dir="ltr"><<a href="mailto:aquagnu@gmail.com" target="_blank">aquagnu@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello Dear List!<br>
<br>
Consider, I retrieve from external source some data. Internally it's<br>
represented as some complex type with `Maybe` fields, even more, some<br>
of fields are record types and have `Maybe` fields too. They are<br>
Maybe's because some information in this data can be missing (user<br>
error or it not very valuable and can be skipped):<br>
<br>
data A = A {<br>
a1 :: Maybe B<br>
... }<br>
data B = B {<br>
b1 :: Maybe C<br>
... }<br>
<br>
I retrieve it from network, files, i.e. external world, then I validate<br>
it, report errors of some missing fields, fix another one (which can be<br>
fixed, for example, replace Nothing with `Just default_value` or even I<br>
can fix `Just wrong` to `Just right`, etc, etc). After all of this, I<br>
know that I have "clean" data, so all my complex types now have `Just<br>
right_value` fields. But I need to process them as optional, with<br>
possible Nothing case! To avoid it I must create copies of `A`, `B`,<br>
etc, where `a1`, `b1` will be `B`, `C`, not `Maybe B`, `Maybe C`. Sure,<br>
it's not a case.<br>
<br>
After processing and filtering, I create, for example, some resulting<br>
objects:<br>
<br>
data Result {<br>
a :: A -- not Maybe!<br>
... }<br>
<br>
And even more: `a::A` in `Result` (I know it, after filtering) will not<br>
contain Nothings, only `Just right_values`s.<br>
<br>
But each function which consumes `A` must do something with possible<br>
Nothing values even after filtering and fixing of `A`s.<br>
<br>
I have, for example, function:<br>
<br>
createResults :: [A] -> [Result]<br>
createResults alst =<br>
...<br>
case of (a1 theA) -><br>
Just right_value -> ...<br>
Nothing -><br>
logError<br>
undefined -- can not happen<br>
<br>
Fun here is: that it happens (I found bug in my filtering<br>
code with this `undefined`). But now I thought about it: what is the<br>
idiomatic way to solve such situation? When you need to have:<br>
<br>
- COMPLEX type WITH Maybes<br>
- the same type WITHOUT Maybes<br>
<br>
Alternative is to keep this Maybes to the very end of processing, what I<br>
don't like. Or to have types copies, which is more terrible, sure.<br>
<br>
PS. I threw IOs away to show only the crux of the problem.<br>
<br>
---<br>
Cheers,<br>
Paul<br>
______________________________<wbr>_________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-<wbr>bin/mailman/listinfo/beginners</a><br>
</blockquote></div><br></div>