New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a function to coerce Cmd Never to Cmd msg #578

Closed
wants to merge 2 commits into
base: master
from

Conversation

Projects
None yet
4 participants
@the-g-man

the-g-man commented Apr 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.

@jvoigtlaender

This comment has been minimized.

Show comment
Hide comment
@jvoigtlaender

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.

Contributor

jvoigtlaender commented Apr 29, 2016

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-g-man

This comment has been minimized.

Show comment
Hide comment
@the-g-man

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...

map (\_ -> Debug.crash "Cmd Never passed to Cmd.sink resulted in a value")

?

@the-g-man the-g-man closed this Apr 29, 2016

@the-g-man the-g-man reopened this Apr 29, 2016

@jvoigtlaender

This comment has been minimized.

Show comment
Hide comment
@jvoigtlaender

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.

Contributor

jvoigtlaender commented Apr 29, 2016

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.

@jvoigtlaender

This comment has been minimized.

Show comment
Hide comment
@jvoigtlaender

jvoigtlaender Apr 29, 2016

Contributor

Yep, should work.

Contributor

jvoigtlaender commented Apr 29, 2016

Yep, should work.

@andersk

This comment has been minimized.

Show comment
Hide comment
@andersk

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 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.

@evancz

This comment has been minimized.

Show comment
Hide comment
@evancz

evancz May 10, 2016

Member

I'd rather not add something like this. There is no motivating example. No reason to add it then.

Member

evancz commented May 10, 2016

I'd rather not add something like this. There is no motivating example. No reason to add it then.

@evancz evancz closed this May 10, 2016

@andersk

This comment has been minimized.

Show comment
Hide comment
@andersk

andersk May 11, 2016

I added my motivating example to #593.

andersk commented May 11, 2016

I added my motivating example to #593.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment