extra
extra copied to clipboard
Make `notNull` for any `Foldable`
Hello, the notNull
defined in Data.List.Extra
, as a composition of not
and null
, is defined only for list, however, de null
function works with any Foldable
, so I think that it would make sense (and it would be very useful) for the notNull
function to also work for any Foldable
.
Some other functions of Data.List.Extra
also would make sense if there where for any Foldable
, such as allSame
and anySame
.
Note that there is https://hackage.haskell.org/package/extra-1.7.9/docs/Data-Foldable-Extra.html, and I'm happy to take patches porting things from List to Foldable with a more generic type. Things like notNull
seem sensible.
Yes, I know about that module, and I think that is the best place for the notNull
function (the null
function is in Data.Foldable
). Also, I have noticed that some functions, such as sumOn'
, already have been defined for any Foldable
in Data.Foldable.Extra
, but the versions of Data.List.Extra
are redefinitions, so if you tray to use them when importing both Data.List.Extra
and Data.Foldable.Extra
you get a Ambiguous occurrence
error:
Prelude Data.List.Extra Data.Foldable.Extra> :t sumOn'
<interactive>:1:1: error:
Ambiguous occurrence ‘sumOn'’
It could refer to either ‘Data.Foldable.Extra.sumOn'’,
imported from ‘Data.Foldable.Extra’
or ‘Data.List.Extra.sumOn'’, imported from ‘Data.List.Extra’
Instead of that, Data.List.Extra
could simple re-export the functions from Data.Foldable.Extra
so that there are the same, such as Data.List
re-exports null
and other functions from Data.Foldable
.
If they weren't redefinitions, they wouldn't have a List type but a Foldable type. I think the most likely solution is for Foldable.Extra to define nearly everything that List.Extra does, and then you are unlikely to be able to need to combine them. There is a big cost in terms of comprehension to abstracting over Foldable, so the List utilities should ideally stay as lists.