Comments (5)
I think this is an issue with the HashMap architecture, and probably has a similar issue with keys.
The only fix I can think of would be altering the underlying Array to bool * obj
pairs to indicate presence. I don't know if that would impact performance enought to make it an undesirable change.
The other alternative is to find an elegant way to prevent option types.
from fsharpx.collections.
I've added pending Expecto tests in https://github.com/fsprojects/FSharpx.Collections/blob/master/tests/FSharpx.Collections.Tests/PersistentHashMapTest.fs and https://github.com/fsprojects/FSharpx.Collections/blob/master/tests/FSharpx.Collections.Tests/TransientHashMapTest.fs
from fsharpx.collections.
Thanks.
bool * obj
sounds sensible. Maybe obj option
could also work, because Some null
cannot be represented by null.
Or if the (potential) performance is a problem, we could just exception guard the add function.
On your suggestion of preventing option types, we could add a and 'S : struct
constraint. Unfortunately, that would be overly restrictive, given that unions do not default to being structs.
It is a shame that F# has a null
constraint, because what we really need is a not null
constraint. Edit: actually, that would not help either. null
is not a "proper value" of an option type, despite null being an internal representation of None.
from fsharpx.collections.
This is terrible. It is quite disappointing when the Option type fails at the only thing it's meant to do. Hope it gets fixed.
In the meantime here is a hack for anyone who still wants to use Options.
(It should only override functionality for case when you use Options and no other case)
type PersistentHashMap() =
static member containsKey key hm = try hm |> PersistentHashMap.find key |> fun x -> Option.isSome x || Option.isNone x with _ -> false
from fsharpx.collections.
It looks to me like the problem here is with INode.find. Note that Clojure has two overloads for this method; the one used for containsKey takes a distinct NOT_FOUND object which is used to detect when the key is not found. Anyway, it looks like INode.find (in current FSharpx.Collections) is only ever used by ContainsKey, so why not change the result type of INode.find to bool and make the appropriate changes to the node implementations? Since INode is internal to the library, I believe that shouldn't be a breaking change.
from fsharpx.collections.
Related Issues (20)
- unique overload for CircularBuffer method 'Enqueue' could not be determined HOT 6
- Circular buffer does not enque arrays properly
- RandomAccessList is not serializable.
- Add LazyList.consLazy HOT 1
- Add static members for F#+ generic operators HOT 1
- Potential net45 support
- AppVeyor builds are not shown as PRs checks. HOT 5
- Travis build sometimes fails on downloading deps via Paket. HOT 3
- Namespaces used by the package and the approach to extending types already present in core lib are not consistent across the package.
- Align Collection Module functions with FSharp.Collections
- Is FSharp.Core >= 4.3.4 still desirable/necessary? HOT 4
- Add conversion of enum value to its string name HOT 1
- Fable compatibility HOT 6
- build fails, need to update FSharp.Formatting HOT 4
- Heap.Tail slow
- Fill gap of functions between `List` and `NonEmptyList`
- Can't use pre-release nuget packages? HOT 10
- Include source files in the Nuget package HOT 5
- Welcome gdziadkiewicz as co-maintainer! HOT 5
- Code style guidance for new structure HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fsharpx.collections.