FSharpPlus
                                
                                 FSharpPlus copied to clipboard
                                
                                    FSharpPlus copied to clipboard
                            
                            
                            
                        Dictionary as Monad
A sort of "infinite" dictionary would allow it to act as a Monad and Applicative.
One limitation with this implementation is that it would require the infinite dictionary to be in the first position of the applicative expression, otherwise it would try to iterate through an infinite dictionary.
There are ways to improve this:
- Create a specific type and match against the type in the applicative implementation. The problem is that the applicative implementation would be linked to only this specific type, though this could be acceptable in order to get applicatives working.
- Make the applicative implementation to get the count first, then iterate with the smaller dict. This is in anycase a good optimization. The problem here is what if both dictionaries are infinites? And how do we signal that it's infinite? Count=MaxInteger? Or maybe use negative numbers, this feels really hacky but it would allow to encode the infinity nature of the dictionary, moreover if we allow adding elements to these dictionaries we can return a negative count of the overridden elements.
This is ready to add either dictionary solution. The error in latest commit is just because a conditional for Fable3 should be added.
There are mainly 2 possible roads:
- Infinite dictionary: Can be anon. Breaks early when trying to iterate. Could be recognized by setting count to -1.
- Defaultable dictionary: Looks like a normal dictionary with all methods, it just return a default value when the key doesn't exists.  It needs a type test in the operation to recognize it.  Doesn't break but it might silently disappear with some operations, like Dict.map.
However: trying hard to make Return for dictionaries maybe is not worth. Sometimes it's better to have a restriction than fighting it back, ie Semigroups.
Closing this in favor of #575
More Info here:
https://www.haskellforall.com/2022/06/defaultable-map-applicative-wrapper-for.html
https://stackoverflow.com/questions/63420753/implementing-applicative-instance-for-dictionaries-map-associated-arrays