elm

Mutually dependant signals

六眼飞鱼酱① 提交于 2019-11-29 07:02:57
Bare question: Is there a way of defining a pair of signals that depend on each other in Elm? Preamble: I'm trying to write a tiny Cookie-clicker-style browser game in which the player is gathering resources, then spending them to purchase autonomous resource-gathering constructs which get more expensive as they're purchased. That implies three relevant signals: gathered (how much resources the player has gathered), spent (how much resource the player has already spent) and cost (how much an upgrade costs). Here's an implementation: module Test where import Mouse import Time port gather :

What does comparable mean in Elm?

牧云@^-^@ 提交于 2019-11-29 06:39:05
I'm having trouble understanding what exactly a comparable is in Elm. Elm seems as confused as I am. On the REPL: > f1 = (<) <function> : comparable -> comparable -> Bool So f1 accepts comparables. > "a" "a" : String > f1 "a" "b" True : Bool So it seems String is comparable. > f2 = (<) 1 <function> : comparable -> Bool So f2 accepts a comparable. > f2 "a" As I infer the type of values flowing through your program, I see a conflict between these two types: comparable String So String is and is not comparable? Why is the type of f2 not number -> Bool ? What other comparables can f2 accept?

How to submit a form in Elm?

↘锁芯ラ 提交于 2019-11-29 02:57:37
问题 It's a really basic question but I didn't find any example. I have a view like this : view address model = div [] [ div [] [ text <|"ID : " ++ toString model.id ] , form [] [ input [ value model.title ] [] , textarea [ value model.content ] [] , button [ onClick address ( SubmitPost model ) ] [ text "Submit" ] // Here is the issue, I want to send my updated model ] ] So it display a form with the content inside. So if I write in my input and textarea to update the content, how do I "catch" my

How do I get the current time in Elm 0.17/0.18?

谁说我不能喝 提交于 2019-11-28 21:27:57
I had asked this question already: How do I get the current time in Elm? And answered it by writing my own ( now deprecated ) variant of start-app: http://package.elm-lang.org/packages/z5h/time-app/1.0.1 Of course the Elm architecture has since changed, and my old way of doing things no longer works, because there are no signals or Time.timestamp . So.... Suppose I build an app with the standard update function signature: update : Msg -> Model -> (Model, Cmd Msg) I'd like to timestamp my model with the time at update. One unacceptable almost-solution is to subscribe to Time.every .

How to set focus on an element in Elm?

血红的双手。 提交于 2019-11-28 19:07:39
How can I set the focus on a Html element in Elm? I tried to set the autofocus attribute on the element and it only sets the focus on the page load. The focus function in the elm-lang/dom package is used to set focus with a Task (without using any port s or JavaScript). Internally it uses requestAnimationFrame to ensure any new DOM updates are rendered before it tries to find the DOM node to focus on. An example use: type Msg = FocusOn String | FocusResult (Result Dom.Error ()) update : Msg -> Model -> ( Model, Cmd Msg ) update msg model = case msg of FocusOn id -> ( model, Dom.focus id |>

FRP - Event streams and Signals - what is lost in using just signals?

女生的网名这么多〃 提交于 2019-11-28 19:03:17
问题 In recent implementations of Classic FRP, for instance reactive-banana, there are event streams and signals, which are step functions (reactive-banana calls them behaviours but they are nevertheless step functions). I've noticed that Elm only uses signals, and doesn't differentiate between signals and event streams. Also, reactive-banana allows to go from event streams to signals (edited: and it's sort of possible to act on behaviours using reactimate' although it not considered good practice

Extract data from a signal

大憨熊 提交于 2019-11-28 10:08:02
问题 I have a signal like this: signal1 = Signal.constant {a=4, b=3, l = []} How do I extract a data from the signal? I have tried Signal.map (\x -> x) signal1 but Signal.map returns another signal. 回答1: If while programming in Elm you ever have questions like: “how do I extract value from a signal?” “how do I change this variable to another value?” “where do I put foldp and what arguments should I pass into it?” you should read The Elm Architecture tutorial and try to implement its code along the

File Upload in Elm

断了今生、忘了曾经 提交于 2019-11-28 09:45:12
How does one upload a file (image or excel) in Elm? Can't seem to find any examples. The answer is fine even if the native code is used. Have seen Data in Elm-Html but it appears files and blobs are not supported. What is the way around this? Simon H I am the author of the library MisterMetaphor refers to. It's easier to use than he explains though. Take a look at how I set up elm-package.json in the example: https://github.com/simonh1000/file-reader/blob/master/example/elm-package.json - just add "native-modules": true, . I have written a blog to support the release of the code for 0.18 and

Mutually dependant signals

走远了吗. 提交于 2019-11-28 00:56:10
问题 Bare question: Is there a way of defining a pair of signals that depend on each other in Elm? Preamble: I'm trying to write a tiny Cookie-clicker-style browser game in which the player is gathering resources, then spending them to purchase autonomous resource-gathering constructs which get more expensive as they're purchased. That implies three relevant signals: gathered (how much resources the player has gathered), spent (how much resource the player has already spent) and cost (how much an

How do I get the current time in Elm 0.17/0.18?

会有一股神秘感。 提交于 2019-11-27 14:05:02
问题 I had asked this question already: How do I get the current time in Elm? And answered it by writing my own ( now deprecated ) variant of start-app: http://package.elm-lang.org/packages/z5h/time-app/1.0.1 Of course the Elm architecture has since changed, and my old way of doing things no longer works, because there are no signals or Time.timestamp . So.... Suppose I build an app with the standard update function signature: update : Msg -> Model -> (Model, Cmd Msg) I'd like to timestamp my