<div dir="auto">No, fromList is too much. Consider<div dir="auto"><br></div><div dir="auto">data Foo a = Foo (IORef String) [a]</div><div dir="auto">  deriving Foldable</div><div dir="auto"><br></div><div dir="auto">What IORef should fromList use?</div><div dir="auto"><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Sep 19, 2021, 2:44 AM Anthony Clayden <<a href="mailto:anthony.d.clayden@gmail.com">anthony.d.clayden@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><font face="arial, sans-serif">(Moving this discussion to glasgow-users. It's just not appropriate on the cafe.)</font></div><div><font face="arial, sans-serif"><br></font></div><font face="arial, sans-serif"><br></font><div><font face="arial, sans-serif">> <span style="color:rgb(0,0,0);font-size:1em;white-space:pre-wrap">I am no longer a novice, and yet would still have a hard time making any </span><span style="color:rgb(0,0,0);font-size:1em;white-space:pre-wrap">use of the laws as written in constructing instances.  Instead, I'd </span><span style="color:rgb(0,0,0);font-size:1em;white-space:pre-wrap">ignore the laws and write a natural intuitive instance, and it would </span><span style="color:rgb(0,0,0);font-size:1em;white-space:pre-wrap">invariably work. </span></font></div><div><span style="color:rgb(0,0,0);font-size:1em;white-space:pre-wrap"><font face="arial, sans-serif"><br></font></span></div><div><font face="arial, sans-serif"><span style="color:rgb(0,0,0);font-size:1em;white-space:pre-wrap">Seems my approach is very similar to Viktor's. </span><span style="color:rgb(0,0,0);font-size:1em;white-space:pre-wrap">My (very informal) understanding of the Laws looks nothing like the docos. I regard Foldable structures as merely more efficient ways to hold a List. Then I expect 'moral equivalences':</span></font></div><div><span style="color:rgb(0,0,0);font-size:1em;white-space:pre-wrap"><font face="arial, sans-serif"><br></font></span></div><div><span style="color:rgb(0,0,0);font-size:1em;white-space:pre-wrap"><font face="arial, sans-serif">>    toList . fromList ~=~ id      -- going via the Foldable structure</font></span></div><div><span style="color:rgb(0,0,0);font-size:1em;white-space:pre-wrap"><font face="arial, sans-serif">>    fromList . toList ~=~ id</font></span></div><div><span style="color:rgb(0,0,0);font-size:1em;white-space:pre-wrap"><font face="arial, sans-serif">>    toList            ~=~ foldr (:) []</font></span></div><div><span style="color:rgb(0,0,0);font-size:1em;white-space:pre-wrap"><font face="arial, sans-serif"><br></font></span></div><div><span style="color:rgb(0,0,0);font-size:1em;white-space:pre-wrap"><font face="arial, sans-serif">But those aren't equalities. 'moral equivalence' means the Lists have the same elements, not necessarily in the same order; the structures have the same elements but possibly in a different arrangement -- that is, in the `Tree` example, there might be `Empty` scattered about, and elements held variously in `Leaf`s vs `Node`s. So more accurately:</font></span></div><div><span style="color:rgb(0,0,0);font-size:1em;white-space:pre-wrap"><font face="arial, sans-serif"><br></font></span></div><div><span style="color:rgb(0,0,0);font-size:1em;white-space:pre-wrap"><font face="arial, sans-serif">>    fromList . toList . fromList === fromList        -- i.e. there's a 'canonical' arrangement</font></span></div><div><span style="color:rgb(0,0,0);font-size:1em;white-space:pre-wrap"><font face="arial, sans-serif">>    toList . fromList . toList   === toList          -- i.e. there's a 'canonical' List ordering</font></span></div><div><span style="color:rgb(0,0,0);font-size:1em;white-space:pre-wrap"><font face="arial, sans-serif"><br></font></span></div><div><font face="arial, sans-serif"><span style="color:rgb(0,0,0);font-size:1em;white-space:pre-wrap">(That triple-journey business is a similar style to defining Lattice pseudocomplements </span><a href="https://en.wikipedia.org/wiki/Pseudocomplement#Properties" target="_blank" rel="noreferrer">https://en.wikipedia.org/wiki/Pseudocomplement#Properties</a> -- if I can chuck in some math theory.)</font></div><div><span style="color:rgb(0,0,0);font-size:1em;white-space:pre-wrap"><font face="arial, sans-serif"><br></font></span></div><div><span style="color:rgb(0,0,0);font-size:1em;white-space:pre-wrap"><font face="arial, sans-serif">I'd expect all other methods to be one of: `reduceStuff === reduceStuff . toList` or `mapStuff === fromList . mapStuff . toList`.</font></span></div><div><span style="color:rgb(0,0,0);font-size:1em;white-space:pre-wrap"><font face="arial, sans-serif"><br></font></span></div><div><span style="color:rgb(0,0,0);font-size:1em;white-space:pre-wrap"><font face="arial, sans-serif">But! there's no method `fromList` in Foldable. Why not?/please explain. (Are there Foldable structures which we can't load from a List? At least assuming the List is finite.) `fromList` is the first thing I write after declaring the datatype, so I can easily load up some test data. There is one example `fromList` in the doco. Is that not generalisable? `foldMap Leaf` would be brutal, but should work? `foldMap singleton` ? (But there's no method `singleton`.)</font></span></div><div><span style="color:rgb(0,0,0);font-size:1em;white-space:pre-wrap"><font face="arial, sans-serif"><br></font></span></div><div><span style="color:rgb(0,0,0);font-size:1em;white-space:pre-wrap"><font face="arial, sans-serif"><br></font></span></div></div>
_______________________________________________<br>
Glasgow-haskell-users mailing list<br>
<a href="mailto:Glasgow-haskell-users@haskell.org" target="_blank" rel="noreferrer">Glasgow-haskell-users@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/glasgow-haskell-users" rel="noreferrer noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/glasgow-haskell-users</a><br>
</blockquote></div>