<div dir="ltr">is it possible to replace Nothing with defaults when A, B are init'ed ?</div><div class="gmail_extra"><br><div class="gmail_quote">On 6 July 2017 at 14:33, 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">Hmm, yes. `Nothing` becomes `Identity default_value`. Respectively `A<br>
Maybe` becomes `A Identity`. I'm not sure will it work but it looks<br>
alluringly ;)<br>
<div class="HOEnZb"><div class="h5"><br>
> > Why..<br>
><br>
> what would<br>
> check::A Maybe -> A Identity<br>
><br>
> do if some A field were Nothing? fill in a default value?<br>
><br>
> On 6 July 2017 at 14:13, Baa <<a href="mailto:aquagnu@gmail.com">aquagnu@gmail.com</a>> wrote:<br>
><br>
> > Imants, I'm not sure that I understood signatures.<br>
> ><br>
> > Why<br>
> > check::A Maybe -> Maybe (A Identity)<br>
> ><br>
> > but not<br>
> > check::A Maybe -> A Identity<br>
> ><br>
> > ?<br>
> ><br>
> > To filter (Nothing items must be throw out)? No more reasons for it?<br>
> ><br>
> ><br>
> > > how about a function (or a Monad Transformer) that checks values<br>
> > > in one place:<br>
> > ><br>
> > > check::A Maybe -> Maybe (A Identity)<br>
> > ><br>
> > > after values were checked, the after-checked functions will deal<br>
> > > with A Identity<br>
> > ><br>
> > > the end result would be<br>
> > > Maybe out<br>
> > ><br>
> > ><br>
> > ><br>
> > > On 6 July 2017 at 13:01, Baa <<a href="mailto:aquagnu@gmail.com">aquagnu@gmail.com</a>> wrote:<br>
> > ><br>
> > > > But will it work if I switch from one monad to another?<br>
> > > > Actually, I have something like piping/conduit, and if I switch<br>
> > > > items in pipe from `A Maybe` to `A Idenitity` - will it work?<br>
> > > > Whether it will be compiled?<br>
> > > ><br>
> > > > Although I certainly can "map" items from one type to another...<br>
> > > > Idea looks interesting sure :)<br>
> > > ><br>
> > > ><br>
> > > > > Identity<br>
> > > > ><br>
> > > > > <a href="http://hackage.haskell.org/package/mtl-2.2.1/docs/" rel="noreferrer" target="_blank">http://hackage.haskell.org/<wbr>package/mtl-2.2.1/docs/</a><br>
> > > > Control-Monad-Identity.html<br>
> > > > ><br>
> > > > > may work:<br>
> > > > ><br>
> > > > > data A m = A {<br>
> > > > > a1 :: m B<br>
> > > > > }<br>
> > > > > data B m = B {<br>
> > > > > b1 :: m C<br>
> > > > > ... }<br>
> > > > ><br>
> > > > > m: Maybe or Identity<br>
> > > > ><br>
> > > > > - any good?<br>
> > > > ><br>
> > > > ><br>
> > > > ><br>
> > > > > On 6 July 2017 at 11:12, Baa <<a href="mailto:aquagnu@gmail.com">aquagnu@gmail.com</a>> wrote:<br>
> > > > ><br>
> > > > > > Hello Dear List!<br>
> > > > > ><br>
> > > > > > Consider, I retrieve from external source some data.<br>
> > > > > > Internally it's represented as some complex type with<br>
> > > > > > `Maybe` fields, even more, some of fields are record types<br>
> > > > > > and have `Maybe` fields too. They are Maybe's because some<br>
> > > > > > information in this data can be missing (user error or it<br>
> > > > > > 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,<br>
> > > > > > then I validate it, report errors of some missing fields,<br>
> > > > > > fix another one (which can be fixed, for example, replace<br>
> > > > > > Nothing with `Just default_value` or even I can fix `Just<br>
> > > > > > wrong` to `Just right`, etc, etc). After all of this, I<br>
> > > > > > know that I have "clean" data, so all my complex types now<br>
> > > > > > have `Just right_value` fields. But I need to process them<br>
> > > > > > as optional, with possible Nothing case! To avoid it I must<br>
> > > > > > create copies of `A`, `B`, etc, where `a1`, `b1` will be<br>
> > > > > > `B`, `C`, not `Maybe B`, `Maybe C`. Sure, it's not a case.<br>
> > > > > ><br>
> > > > > > After processing and filtering, I create, for example, some<br>
> > > > > > resulting objects:<br>
> > > > > ><br>
> > > > > > data Result {<br>
> > > > > > a :: A -- not Maybe!<br>
> > > > > > ... }<br>
> > > > > ><br>
> > > > > > And even more: `a::A` in `Result` (I know it, after<br>
> > > > > > filtering) will not contain Nothings, only `Just<br>
> > > > > > right_values`s.<br>
> > > > > ><br>
> > > > > > But each function which consumes `A` must do something with<br>
> > > > > > possible Nothing values even after filtering and fixing of<br>
> > > > > > `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:<br>
> > > > > > what is the idiomatic way to solve such situation? When you<br>
> > > > > > 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<br>
> > > > > > processing, what I don't like. Or to have types copies,<br>
> > > > > > 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>
> > > > > ><br>
> > > ><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>
> > > ><br>
> ><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>
> ><br>
<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>
</div></div></blockquote></div><br></div>