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 upAdd Maybe.unsafe? #215
Comments
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
haf
Apr 21, 2015
Have you considered adding structural typing on top of lists, to avoid this use case? That way head could be defined totally on the type of non-empty lists.
haf
commented
Apr 21, 2015
|
Have you considered adding structural typing on top of lists, to avoid this use case? That way head could be defined totally on the type of non-empty lists. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
lfairy
Apr 21, 2015
I'd suggest requiring a message as well, so that in the (hopefully rare) case that it fails, we'd get some context as to what happened.
lfairy
commented
Apr 21, 2015
|
I'd suggest requiring a message as well, so that in the (hopefully rare) case that it fails, we'd get some context as to what happened. |
sindikat
referenced this issue
Aug 23, 2015
Merged
Many new functions, including maybe, unsafe, ap, traverse, sequence #5
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
nixpulvis
Jan 6, 2016
Taking a note from Rust, I've always liked the name expect for this. Unsafe feels weird to me.
nixpulvis
commented
Jan 6, 2016
|
Taking a note from Rust, I've always liked the name |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
jvoigtlaender
Jul 8, 2016
Contributor
Maybe close this? Like https://github.com/elm-lang/core/issues/216, it doesn't seem to have gotten traction.
|
Maybe close this? Like https://github.com/elm-lang/core/issues/216, it doesn't seem to have gotten traction. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
evancz
Jul 9, 2016
Member
Yeah, I don't think it's necessary given that we made a lot more things return Maybe and it has been pretty fine.
|
Yeah, I don't think it's necessary given that we made a lot more things return |
evancz commentedApr 15, 2015
With lots of core functions becoming total, it makes sense to consider having a central way to live dangerously.
The
unsafefunction extracts a value or crashes. But why introduce such a crazy thing?There are a tiny set of cases where you know it is going to be fine and might want this. For example, imagine you have a
Dictand the values are lists. You would never put an empty list in your dictionary, that would be silly, so you know you can always get elements of the list. I have seen this a few times programming in languages like Elm.The nice part of
unsafeis that it makes the risks extremely explicit. Rather than ever creating an unsafe function, you can always return aMaybeand extract it withunsafe. This way, you can search through code for any occurrences ofunsafeand quickly identify any risks. It also is a good sign of “maybe you should try to say the same thing a different way?”This feels similar in spirit to
Debug.crashwhich also makes risks very obvious.Can you find uses of this in your code? Please share so we can evaluate if it is a good idea!