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 upRe-introducing `Maybe.isNothing` #164
Conversation
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
jvoigtlaender
Mar 11, 2015
Contributor
Can I bump this again? I'm still lacking any clue about what is considered harmful about isNothing. And as expressed above, pushing people into either redundantly re-defining it again and again, or into using something like ((==) Nothing), will most likely be regretted down the road. (Also, there seems to be no recommendation to use ((==) []) instead of isEmpty in the list case.)
|
Can I bump this again? I'm still lacking any clue about what is considered harmful about |
This was referenced Mar 13, 2015
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
This seems useful and harmless. +1 in my book. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
mgold
Jun 11, 2015
Contributor
Seems harmless. filterMap handles a lot of common cases but the double clicks example shows that it's not a silver bullet.
|
Seems harmless. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
jvoigtlaender
Sep 11, 2015
Contributor
Can this be added to https://github.com/elm-lang/core/issues/322?
|
Can this be added to https://github.com/elm-lang/core/issues/322? |
evancz
closed this
Sep 11, 2015
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
evancz
Sep 11, 2015
Member
The process is to go through *-extra, which it looks like has happened here.
I'd like to see the arguments for why things are useful be folded into that process. So when it comes time to review the list and maybe and result and whatever else libraries, we have all that stuff easily accessible. I am not sure if that happened in this case, so I'll add it to the meta issue. In the future, try to put it in the extra process though.
|
The process is to go through *-extra, which it looks like has happened here. I'd like to see the arguments for why things are useful be folded into that process. So when it comes time to review the list and maybe and result and whatever else libraries, we have all that stuff easily accessible. I am not sure if that happened in this case, so I'll add it to the meta issue. In the future, try to put it in the extra process though. |
jvoigtlaender
deleted the
jvoigtlaender:isNothing
branch
Sep 11, 2015
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
mgold
Sep 11, 2015
Contributor
I think that it only makes sense to have either both isJust and isNothing, or neither. They do come in handy when you don't want to do a pattern match.
|
I think that it only makes sense to have either both |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
jvoigtlaender
Sep 11, 2015
Contributor
And yet we have only List.isEmpty, not also List.containsSomething.
I'm not sure Maybe.isNothing and Maybe.isJust are equally useful.
What is an example where one would prefer isJust over a pattern match (and over isNothing)?
|
And yet we have only I'm not sure What is an example where one would prefer |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
mgold
Sep 12, 2015
Contributor
Okay, that's an interesting point. Another function that is sometimes useful is dropNothings : List (Maybe a) -> List a but you can usually work around that with List.concatMap.
|
Okay, that's an interesting point. Another function that is sometimes useful is |
jvoigtlaender commentedFeb 7, 2015
One motivating example:
It's a pain to have to write something like
(\m -> case m of {Nothing -> True; _ -> False})instead ofisNothingabove. (Update: That one-line inline definition will not even be valid syntax in Elm 0.16 anymore, since support for bracketed case expressions is being removed. This only makes it more painful to not have a functionisNothingreadily available.)One possible rebuttal:
"But you could write
((==) Nothing)instead of the above explicit lambda-expression with pattern-matching."My answer: That's not really good in general. It pretends that
(==)works okay on all types (note thatisNothing : Maybe a -> Boolis polymorphic ina). But in the future, to prevent runtime errors like that arising fromidentity == (\x -> x), it might come to pass that the compiler restricts uses of(==). It would have to restrict them not only on function types, but also somehow on polymorphism (since anyacould turn into ab->c). Then suddenly((==) Nothing)would be less generally applicable thanisNothing.Another possible rebuttal:
"Uses of
fromJustandisNothingsmell bad. Pattern-matching should be used instead."My answer: I'm not proposing to re-inroduce
fromJust. I yet have to see evidence of a piece of code that usesisNothing(but notfromJust) and seems bad style because of that use ofisNothing. Also my example above uses onlyisNothing, notfromJust. I don't know what there could be to dislike about the use ofisNothingin there. (See also this post.)A cheap argument from my side:
We do have
List.isEmpty(but notisNotEmpty,head : [a] -> a, andtail : [a] -> [a]) in the standard lib. The consistent thing to do w.r.t.Maybeis to haveMaybe.isNothing(but notisJustandfromJust : Maybe a -> a) in the standard lib.Evidence from other people's projects:
Searching GitHub gives the following places where Elm users have felt a need to introduce
isNothingin their own code.(Disclosure: Two of the above are students of mine. I don't think that is a relevant bias though.)
In addition, there are various GitHub hits where Elm users have used
isNothingwithout defining it themselves. Apparently these projects are not yet upgraded from 0.13 to 0.14. If they were, maybe not all of these uses could be replaced by pattern-matching without pain, so at least in some of these cases it would be likely that these people would also start introducing their own implementation ofisNothing:I don't think it is possible to dismiss all the uses above with "
isNothingis bad style, use pattern-matching instead".Note that it is also well possible that additional uses exist where people have simply chosen a different name but implemented the same functionality.
About the process here
I know that the proper process to suggest an addition to the standard lib now is to first create a new package like
elm-maybe-extras, put the new function there, wait a while to see whether it gets used. But let's be realistic. For a simple function likeMaybe.isNothing, almost nobody will make the effort to add the required line toelm-package.jsonand add the required line to import the extra module into their code, just to be able to use that simple function which can just as easily be defined in one's own code. So what would happen is that the extra package would not get used but still we would see the proliferation of repeated definitions ofisNothingin different people's projects. The only way I see to prevent such redundancy is to addisNothingright to the standard lib.