Question

I want to create a function that has this type :

 Signal x -> x

as an example

my_return : Signal x -> x
my_return x = x     -- this is the part I have wrong

Could I please get an example of a function that simply takes a Signal x and returns an x?

Was it helpful?

Solution

You can't do that in Elm (and in any pure functional language).

What Elm does is providing you a way to manipulate the inputs and create a output through a thing called lifting.

lift : (a -> b) -> Signal a -> Signal b

So suppose we have my_return with type a -> a then we could write this

my_return : a -> a
my_return x = x

lift my_return input

Through combining all those functions, you get a program that produces output (of type Signal Element).

import Mouse

my_return : a -> a
my_return x = x

main : Signal Element
main = lift (asText . my_return) Mouse.position
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top