Skip to content

Dictionary as Monad - #448

Draft
gusty wants to merge 21 commits into
masterfrom
gusty-dict-applicative
Draft

Dictionary as Monad#448
gusty wants to merge 21 commits into
masterfrom
gusty-dict-applicative

Conversation

@gusty

@gustygusty commented Jun 3, 2021

Copy link
Copy Markdown
Member

A sort of "infinite" dictionary would allow it to act as a Monad and Applicative.

@gusty
gustyforce-pushed the gusty-dict-applicative branch from e86178a to c02d157CompareJune 4, 2021 18:06
@gusty
gustyforce-pushed the gusty-dict-applicative branch from c02d157 to 25c00cdCompareJune 4, 2021 18:10
@gusty

gusty commented Jun 4, 2021

Copy link
Copy Markdown
MemberAuthor

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.

@gusty
gustyforce-pushed the master branch 2 times, most recently from 32f5c4a to f2d1afdCompareAugust 30, 2022 17:21
@gusty
gustyforce-pushed the master branch 4 times, most recently from 5c69948 to 9ca5706CompareSeptember 19, 2022 15:20
@gusty
gustyforce-pushed the master branch 2 times, most recently from 5b61ffc to ad56a34CompareDecember 2, 2022 10:55
@gusty
gustyforce-pushed the master branch 12 times, most recently from 429e6fc to 8fb276cCompareFebruary 22, 2023 07:30
@gusty
gustyforce-pushed the gusty-dict-applicative branch 2 times, most recently from 018d7cb to 25c00cdCompareDecember 19, 2023 08:43
@gusty
gustyforce-pushed the gusty-dict-applicative branch from 984e26f to bfa151dCompareDecember 19, 2023 09:10
@gusty
gustyforce-pushed the gusty-dict-applicative branch from b64b3fc to 88bd6b9CompareDecember 19, 2023 09:27
@gustygusty closed this Dec 20, 2023
@gustygusty mentioned this pull request Jun 4, 2025
@gustygusty reopened this Jun 11, 2025
Comment threadsrc/FSharpPlus/Extensions/Dict.fs Outdated
@gusty

Copy link
Copy Markdown
MemberAuthor

I re-opened it just to experiment, but it doesn't mean that I'm proposing to merge it, as I still think it will break LSP.

Co-authored-by: Hadrian Tang <hadrianwttang@outlook.com>
@gusty
gustyforce-pushed the gusty-dict-applicative branch from 23de96a to ebc40efCompareJune 14, 2025 09:40
@gusty
gustyforce-pushed the gusty-dict-applicative branch from 2769fd0 to 221911cCompareJune 15, 2025 09:10
@gustygusty changed the title Applicative dictionaryDictionary as MonadJun 15, 2025
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@gusty@Happypig375