You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
First of all, thanks for picking this up for Elm 0.16!
I was trying to use elm-console in a context where I have a Task that produces a String, and I want to write this string to the console. Here's some code to illustrate:
task:Task()Stringtask =Task.succeed "String"io:Task() (IO())
io =Task.map Console.putStrLn task
port runner:Task() (Signal (Taskx()))
port runner =Task.map Console.run io
Now, in this case the Task is obviously trivial, but imagine code where there really was an substantial Task involved that ultimately could be mapped to a String.
The code above will compile, but it doesn't really make any sense (and doesn't work), because a Task which results in a signal of tasks isn't really sensible within Elm, for a variety of reasons. So, it's a dead end.
So, I was trying to conceive of what is missing here. One way of thinking about it would be that we need a function of this form:
fromTask:Taskxa->IO (x, a)
Now, one complication for implementation would be arranging for the task to be executed when the IO is executed, but that doesn't seem impossible.
If one had this "bridge" between Task-world and IO-world, I think it would cover a lot of cases.
So, I'm wondering whether I'm thinking about this the right way -- is there a better way to imagine how this might work?
In passing, I think there are similar puzzles re: Signals and IO ... for instance, what if you had a Signal String and you wanted to write each String to the console as it arrived? I'm not sure how you'd do that either, but I haven't thought much about it.
The text was updated successfully, but these errors were encountered:
OK, I belatedly realized that my practical problem was easy enough to solve -- it's easy to create a Task that itself writes a String to the console. So I don't really need to be in IO world particularly, just to get a string written.
However, I think the general issue is still potentially interesting.
First of all, thanks for picking this up for Elm 0.16!
I was trying to use elm-console in a context where I have a
Task
that produces aString
, and I want to write this string to the console. Here's some code to illustrate:Now, in this case the
Task
is obviously trivial, but imagine code where there really was an substantialTask
involved that ultimately could be mapped to aString
.The code above will compile, but it doesn't really make any sense (and doesn't work), because a
Task
which results in a signal of tasks isn't really sensible within Elm, for a variety of reasons. So, it's a dead end.So, I was trying to conceive of what is missing here. One way of thinking about it would be that we need a function of this form:
Now, one complication for implementation would be arranging for the task to be executed when the IO is executed, but that doesn't seem impossible.
If one had this "bridge" between Task-world and IO-world, I think it would cover a lot of cases.
Some others one could imagine are:
So, I'm wondering whether I'm thinking about this the right way -- is there a better way to imagine how this might work?
In passing, I think there are similar puzzles re: Signals and IO ... for instance, what if you had a
Signal String
and you wanted to write eachString
to the console as it arrived? I'm not sure how you'd do that either, but I haven't thought much about it.The text was updated successfully, but these errors were encountered: