Elm – functional reactive language for interactive applications
1–10 of 12 posts
Re: Elm – functional reactive language for interactive applications
#2However, can someone please tell me why Elm needs two kinds of values? There are simple values and then there are "signals". I don't understand why you need to make the distinction.
If you want to apply a function to a signal, you need to use "lift". From the Elm documentation:
"The lift functions are used to apply a normal function like sqrt to a signal of values such as Mouse.x. So the expression (lift sqrt Mouse.x) evaluates to a signal in which the current value is equal to the square root of the current x-coordinate of the mouse."
Why can't you eliminate "lift" and just have all values be signals? Then "lift sqrt Mouse.x" would become "sqrt Mouse.x". (Which makes a lot more sense, if you ask me...)
Re: Elm – functional reactive language for interactive applications
#3I think Elm is very interesting and inspiring. The time travel debugger especially is very impressive. However, can someone please tell me why Elm needs two kinds of values? There are simple values and then there are "signals". I don't understand why you need to make the distinction. If you want to apply a function to a signal, you need to use "lift". From the Elm documentation: "The lift functions are used to apply…
Re: Elm – functional reactive language for interactive applications
#4I think Elm is very interesting and inspiring. The time travel debugger especially is very impressive. However, can someone please tell me why Elm needs two kinds of values? There are simple values and then there are "signals". I don't understand why you need to make the distinction. If you want to apply a function to a signal, you need to use "lift". From the Elm documentation: "The lift functions are used to apply…
Because not all values depend on/change with time. A euclidean distance function is the same no matter when in time it exists. But, the distance between a player and an enemy is something that changes with time. So, you'd want to lift the euclidean distance function onto a signal like 'lift2 distance playerPos enemyPos'. I don't actually program in Haskell or Elm, so I don't know if that is the correct syntax, but you get the idea.
Re: Elm – functional reactive language for interactive applications
#5I think Elm is very interesting and inspiring. The time travel debugger especially is very impressive. However, can someone please tell me why Elm needs two kinds of values? There are simple values and then there are "signals". I don't understand why you need to make the distinction. If you want to apply a function to a signal, you need to use "lift". From the Elm documentation: "The lift functions are used to apply…
>However, can someone please tell me why Elm needs two kinds of values? Because not all values depend on/change with time. A euclidean distance function is the same no matter when in time it exists. But, the distance between a player and an enemy is something that changes with time. So, you'd want to lift the euclidean distance function onto a signal like 'lift2 distance playerPos enemyPos'. I don't actually program…
Re: Elm – functional reactive language for interactive applications
#6Earlier quoted context omitted.
>However, can someone please tell me why Elm needs two kinds of values? Because not all values depend on/change with time. A euclidean distance function is the same no matter when in time it exists. But, the distance between a player and an enemy is something that changes with time. So, you'd want to lift the euclidean distance function onto a signal like 'lift2 distance playerPos enemyPos'. I don't actually program…
But why not make the "lifting" implicit? If you put a signal into "distance", you get a signal back.
Re: Elm – functional reactive language for interactive applications
#7I think Elm is very interesting and inspiring. The time travel debugger especially is very impressive. However, can someone please tell me why Elm needs two kinds of values? There are simple values and then there are "signals". I don't understand why you need to make the distinction. If you want to apply a function to a signal, you need to use "lift". From the Elm documentation: "The lift functions are used to apply…
So why lift? If we receive a value through IO (e.g. Mouse.x) we can't determine the value beforehand, thus it is impure. Let's say we create a function to increase Mouse.x by a certain number, it's signature would be this: Signal a -> a -> Signal a. If a function takes a Signal as argument it must return a Signal as well. So now we're writing impure functions thus losing a lot of safety. Instead we can write pure functions where we don't have to worry about outside input and still apply impure value to it through lift. I'm not writing Haskell professionally, however I try to apply this technique in my daily work with other languages. Create as many modular functions that don't interact with IO as possible, and try to limit yourself of retrieving IO values in too many different places in your code.
I personally love IO Monad / Signal, they taught me how to write better code in other languages. It might seems like a hassle at first but if you get into it you'll see their charm :)
Re: Elm – functional reactive language for interactive applications
#8Earlier quoted context omitted.
>However, can someone please tell me why Elm needs two kinds of values? Because not all values depend on/change with time. A euclidean distance function is the same no matter when in time it exists. But, the distance between a player and an enemy is something that changes with time. So, you'd want to lift the euclidean distance function onto a signal like 'lift2 distance playerPos enemyPos'. I don't actually program…
But why not make the "lifting" implicit? If you put a signal into "distance", you get a signal back.
If all you want is syntactic sugar, Elm has infix lift operators so:
let p = lift2 (+) Mouse.x Mouse.y
becomes: let p = (+)
If you don't like that, Haskell has `do` notation. If Elm also had it, you could do: let p = do
x Re: Elm – functional reactive language for interactive applications
#9http://elm-lang.org/edit/examples/Intermediate/Mario.elm
Otherwise it looks great. :)
Re: Elm – functional reactive language for interactive applications
#10I think Elm is very interesting and inspiring. The time travel debugger especially is very impressive. However, can someone please tell me why Elm needs two kinds of values? There are simple values and then there are "signals". I don't understand why you need to make the distinction. If you want to apply a function to a signal, you need to use "lift". From the Elm documentation: "The lift functions are used to apply…
;)