Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upBool values cannot be the member of Set #329
Comments
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
jvoigtlaender
Aug 4, 2015
Contributor
Set is implemented via Dict, and Dict is implemented via some sort of balanced trees, operations on which do in fact require a total order on entries/keys. So the implementation indeed requires comparable for types that should be put into a Set or used as key in a Dict.
So probably the right feature request here is that Bool should become comparable. Making all union types comparable would be more complicated, but special-casing for Bool could make sense.
|
So probably the right feature request here is that |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
evancz
Aug 4, 2015
Member
Why do you want a set of booleans? Any case I can think of can also be handled just by booleans.
|
Why do you want a set of booleans? Any case I can think of can also be handled just by booleans. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
jvoigtlaender
Aug 4, 2015
Contributor
Well, what about a set of tuples, some tuple component of which is a boolean? Certainly that's a valid use case that is not covered by just booleans alone?
|
Well, what about a set of tuples, some tuple component of which is a boolean? Certainly that's a valid use case that is not covered by just booleans alone? |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
evancz
Aug 4, 2015
Member
Ah, I was just looking at the example given. Nested stuff makes sense. Let's hear @jinjor's specific case though.
|
Ah, I was just looking at the example given. Nested stuff makes sense. Let's hear @jinjor's specific case though. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
jinjor
Aug 4, 2015
Contributor
Yeah, exactly the case @jvoigtlaender said. (Sorry, the example above is not real one. )
Here is the specific case in my WebRTC app.
type alias Peer = Int
type alias MediaType = String
type alias Upstream = Bool
type alias Connection = (Peer, MediaType, Upstream)
type alias Model =
{ connections : Set Connection
, videoUrls : Dict Connection String
...
}Oh, now I found MediaType can also be written as an union type, like type MediaType = Audio | Video.
|
Yeah, exactly the case @jvoigtlaender said. (Sorry, the example above is not real one. ) Here is the specific case in my WebRTC app. type alias Peer = Int
type alias MediaType = String
type alias Upstream = Bool
type alias Connection = (Peer, MediaType, Upstream)
type alias Model =
{ connections : Set Connection
, videoUrls : Dict Connection String
...
}Oh, now I found |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
evancz
Aug 5, 2015
Member
Okay, makes sense. I don't know what the short term solution is, but I made an aggregate issue at elm/compiler#1008 so we can keep track of all the issues along these lines. Hopefully the different perspectives will help us come to a good answer.
|
Okay, makes sense. I don't know what the short term solution is, but I made an aggregate issue at elm/compiler#1008 so we can keep track of all the issues along these lines. Hopefully the different perspectives will help us come to a good answer. |
jinjor commentedAug 4, 2015
I'm facing a problem with making a Set that contains Bool values.
And also, lists or tuples that contains Bool cause the same trouble.
Here is the simple example and the error message.
I understand what the compiler is saying, but not sure why Set or Dict keys need to be
comparable. Should they always be sorted?I think the possible solutions are...
comparablecomparableAny ideas? Or is there any workaround?
Thanks.