Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

About reference transparency being broken and whether or not to modify this package. #76

Open
yukikurage opened this issue Oct 22, 2022 · 0 comments

Comments

@yukikurage
Copy link

First, every function.

tmp = every 1000.0

main :: Effect Unit
main = launchAff_ do
  Aff.delay $ Milliseconds 500.0
  let
    pulse = tmp
  liftEffect $ runSignal $ pulse ~> logShow

outputs

75.52480700612068
1076.4696190059185
2078.1452220082283
3079.518830999732
4080.8751610070467
5081.603973001242
...
main :: Effect Unit
main = launchAff_ do
  Aff.delay $ Milliseconds 500.0
  let
    pulse = every 1000.0
  liftEffect $ runSignal $ pulse ~> logShow

outputs

578.351668998599
1580.3739890009165
2580.902148991823
3582.3207959979773
4583.194288998842
...

These behaviors are different, but what we have done is replace the bindings.

Next, merge function

main :: Effect Unit
main = do
  channel1 <- channel true
  channel2 <- channel true
  let
    mergedSignal = merge (subscribe channel1) (subscribe channel2)
  send channel2 false
  logShow =<< get mergedSignal

output false

main :: Effect Unit
main = do
  channel1 <- channel true
  channel2 <- channel true
  send channel2 false
  let
    mergedSignal = merge (subscribe channel1) (subscribe channel2)
  logShow =<< get mergedSignal

outputs true

For the same reason, filters are not referentially transparent either.

I would like to modify these APIs, but in fact, this package references Elm's APIs, so it may not be a good idea to make direct changes.
In other words, there are two options

  • Modify the this Signal package
  • Create a new, modified package

Do you have any suggestions on the pros and cons of modifying this package, or any other suggestions?

@yukikurage yukikurage changed the title About reference transparency being breached and whether or not to modify this package. About reference transparency being broken and whether or not to modify this package. Oct 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant