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 a function to coerce Cmd Never to Cmd msg #578
Conversation
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
jvoigtlaender
Apr 29, 2016
Contributor
The strict (instead of lazy) semantics of Elm will hit you in the face as soon as you try to use the sink-function in your program. Hint: the Debug.crash call there is not a good idea.
|
The strict (instead of lazy) semantics of Elm will hit you in the face as soon as you try to use the sink-function in your program. Hint: the Debug.crash call there is not a good idea. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
the-g-man
Apr 29, 2016
Actually, as it is, it won't even type-check. It was written in haste at work while waiting for something to compile.
How about...
map (\_ -> Debug.crash "Cmd Never passed to Cmd.sink resulted in a value")
?
the-g-man
commented
Apr 29, 2016
|
Actually, as it is, it won't even type-check. It was written in haste at work while waiting for something to compile. How about...
? |
the-g-man
closed this
Apr 29, 2016
the-g-man
reopened this
Apr 29, 2016
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
jvoigtlaender
Apr 29, 2016
Contributor
Actually, as it is, it won't even type-check.
Oh, of course it would have type-checked. The type of Debug.crash is String -> a, polymorphic in a, so it would have been instantiable to an arbitrary function type as return type well enough.
How about...
Yes, that's better in that it won't immediately crash. Whether it does exactly what you want depends on the definition of Cmd.map, which I haven't looked into.
Oh, of course it would have type-checked. The type of
Yes, that's better in that it won't immediately crash. Whether it does exactly what you want depends on the definition of |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
Yep, should work. |
andersk
referenced this pull request
May 10, 2016
Closed
Add the empty function never : Never -> a #593
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
andersk
May 10, 2016
What do you think about adding absurd : Never -> a (#593), thereby solving this with Cmd.map absurd? It’s more general than Cmd Never -> Cmd msg, and safer than making the user write a Debug.crash call.
andersk
commented
May 10, 2016
•
|
What do you think about adding |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
evancz
May 10, 2016
Member
I'd rather not add something like this. There is no motivating example. No reason to add it then.
|
I'd rather not add something like this. There is no motivating example. No reason to add it then. |
evancz
closed this
May 10, 2016
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
andersk
commented
May 11, 2016
|
I added my motivating example to #593. |
the-g-man commentedApr 29, 2016
This is more a suggestion than a pull request but it seemed easiest to illustrate the idea by writing the code.
There should be an idiom for expressing the idea of a sink effect - i.e. one that isn't expected to emit any value when it is called. A possible example might be writing to the storage API. The obvious way to do this is to use a
Cmd Never. But as things stand there isn't an idiomatic way to incorporate this into an application loop.Implementing the idiom is trivial but might be surprising if it appeared naked in application code. It seems like it might be better to wrap it up in a core function to create a common idiom for these cases.