I've been looking into it more recently, and there are a few things I don't quite understand about the Http library. Mainly, I think I don't quite see why Http.send has type:
Signal (Request a) -> Signal (Response String)
instead of just
Request a -> Signal (Response String)
as you would expect a typical function with side effects to have (which would allow to sequence it with others using Kleisli composition, maybe? although maybe not due to the Signal-is-not-a-monad limitation?).
--mt-i--
You received this message because you are subscribed to the Google Groups "Elm Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Signals are not sufficiently expressive to use Kleisli composition; they are only Applicative Functors and not Monads. This is an intentional restriction. In this specific case, the point of HTTP.send is that you can fetch some new content each time an input field changes, as an example.
For your last question, I suspect you might need some clever use of foldp. Not quite sure what the use case is, perhaps there's a better way to solve it.
I think a general solution would be to add an inverse of combine to Elm: uncombine : Signal [a] -> [Signal a]. Although combine is implemented in pure Elm, uncombine cannot be implemented in pure Elm (AFAIK).
But I think it can be handy and I can't find a way in which it can jeopardise the Signal not being a Monad.Something similar that can be used right now is the following:-- extract gives a list with a length of _amount_, with Signals of Just when the list in _s_ has a corresponding value and Signals of Nothing after that.extract : Int -> Signal [a] -> [Signal (Maybe a)]extract amount s = if amount == 0 then [] else(mHead <~ s) :: (extract (amount-1) <| (maybe [] id . mTail) <~ s)
Does this help?
I see, thanks. While I did understand why Http.send returns a signal, it seemed strange to me that it would take one as input (as opposed to, say, printStrLn in Haskell having type String -> IO () and not IO String -> IO ()). But since Kleisli composition isn't possible, it makes sense: a function that returns "Signal b" cannot be lifted anymore, so it has to take "Signal a" as input for any parameter where one may want to pass it the contents of a signal at some point. Is that correct?
Indeed, that would solve the problem completely! If there is no theoretical obstacle to having such a function, it would be very helpful. Can I make it a feature wish?
--
You received this message because you are subscribed to a topic in the Google Groups "Elm Discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/elm-discuss/iUdZewHmYoo/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to elm-discuss...@googlegroups.com.