Re: Was: [Haskell-cafe] Haskell reference documentation, laws first or laws last?
[email protected] Sun, 19 Sep 2021 11:39:55 +0000
| Newsgroups | gmane.comp.lang.haskell.glasgow.user |
|---|---|
| Message-ID | <e1qT7KqUlVzIWmQY81bg7tR3GQWg7nej88dgMChKhlUsm4uEwtW3IuI7pHyMO45HrHjMHLMA70yrzsBQcNJ8NbRn-xwwwI78UKOcGvCjT3I=@coot.me> |
Another example are non-empty containers, e.g. for `NonEmpty` one cannot have a total `fromList :: [a] -> NonEmpty a`. Regards, Marcin Sent with ProtonMail Secure Email. ‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐ On Sunday, September 19th, 2021 at 08:49, David Feuer <[email protected]> wrote: > No, fromList is too much. Consider > > data Foo a = Foo (IORef String) [a] deriving Foldable > > What IORef should fromList use? > > On Sun, Sep 19, 2021, 2:44 AM Anthony Clayden <[email protected]> wrote: > > > (Moving this discussion to glasgow-users. It's just not appropriate on the cafe.) > > > > > I am no longer a novice, and yet would still have a hard time making any use of the laws as written in constructing instances. Instead, I'd ignore the laws and write a natural intuitive instance, and it would invariably work. > > > > Seems my approach is very similar to Viktor's. 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': > > > > > toList . fromList ~=~ id -- going via the Foldable structure> fromList . toList ~=~ id> toList ~=~ foldr (:) [] > > > > 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: > > > > > fromList . toList . fromList === fromList -- i.e. there's a 'canonical' arrangement> toList . fromList . toList === toList -- i.e. there's a 'canonical' List ordering > > > > (That triple-journey business is a similar style to defining Lattice pseudocomplements https://en.wikipedia.org/wiki/Pseudocomplement#Properties -- if I can chuck in some math theory.) > > > > I'd expect all other methods to be one of: `reduceStuff === reduceStuff . toList` or `mapStuff === fromList . mapStuff . toList`. > > > > 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`.) > > > > _______________________________________________ > > > > Glasgow-haskell-users mailing list > > > > [email protected] > > > > http://mail.haskell.org/cgi-bin/mailman/listinfo/glasgow-haskell-users _______________________________________________ Glasgow-haskell-users mailing list [email protected] http://mail.haskell.org/cgi-bin/mailman/listinfo/glasgow-haskell-users
signature.asc
(application/pgp-signature, 509 B)
-----BEGIN PGP SIGNATURE----- Version: ProtonMail wsBzBAEBCAAGBQJhRyFtACEJELzb3fH7p2X/FiEEoEYDG+01s7povBmrvNvd 8funZf86DwgAtjolVxDR+lbVWBDA61RHmJ+hCbuIY2/+X9mzBqxmp62P/YuU mvDD8CPiVpMipXdtQX8NW9yHdCTPhTWK1Jk3HbpKhKkKv1gofmMJpkIAaHtb EtBgRybXpT08+jSMDai4DVlD52WtJNDSCHfa+/Jb4wixk3o7HHi5u5LR9I48 fyl62EqKtSyF6Rq3pbxOOhi0HnT9v6ftdxmmmYNy/vzt8Rc3kV1hUXGIgIQ8 CA3QQ6ge2fhnevD6+Ner1unPXadcJjSQQ/YtsVn7MeEi9cZbs+5jzu2GdAok XsF1iF9Qr+Iq78zGEVZxT+c7wM1Ag9/bOWzPtRH6K9Tu2KVHCubvHQ== =m2fx -----END PGP SIGNATURE-----