Skip to content

Dictionary as Monad #448

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 21 commits into
base: master
Choose a base branch
from
Draft

Dictionary as Monad #448

wants to merge 21 commits into from

Conversation

gusty
Copy link
Member

@gusty gusty commented Jun 3, 2021

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

@gusty gusty force-pushed the gusty-dict-applicative branch from e86178a to c02d157 Compare June 4, 2021 18:06
@gusty gusty force-pushed the gusty-dict-applicative branch from c02d157 to 25c00cd Compare June 4, 2021 18:10
@gusty
Copy link
Member Author

gusty commented Jun 4, 2021

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 gusty force-pushed the master branch 2 times, most recently from 32f5c4a to f2d1afd Compare August 30, 2022 17:21
@gusty gusty force-pushed the master branch 4 times, most recently from 5c69948 to 9ca5706 Compare September 19, 2022 15:20
@gusty gusty force-pushed the master branch 2 times, most recently from 5b61ffc to ad56a34 Compare December 2, 2022 10:55
@gusty gusty force-pushed the master branch 12 times, most recently from 429e6fc to 8fb276c Compare February 22, 2023 07:30
@gusty gusty reopened this Dec 19, 2023
@gusty gusty force-pushed the gusty-dict-applicative branch 3 times, most recently from 018d7cb to 25c00cd Compare December 19, 2023 08:43
@gusty gusty force-pushed the gusty-dict-applicative branch from 984e26f to bfa151d Compare December 19, 2023 09:10
@gusty gusty force-pushed the gusty-dict-applicative branch from b64b3fc to 88bd6b9 Compare December 19, 2023 09:27
@gusty gusty closed this Dec 20, 2023
@gusty gusty reopened this Jun 11, 2025
@gusty
Copy link
Member Author

gusty commented Jun 13, 2025

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 <[email protected]>
@gusty gusty force-pushed the gusty-dict-applicative branch from 23de96a to ebc40ef Compare June 14, 2025 09:40
@gusty gusty force-pushed the gusty-dict-applicative branch from 2769fd0 to 221911c Compare June 15, 2025 09:10
@gusty gusty changed the title Applicative dictionary Dictionary as Monad Jun 15, 2025
@gusty gusty force-pushed the gusty-dict-applicative branch from 5d8211a to bf1d623 Compare June 16, 2025 14:23
Sign up for free to 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