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

Eliminate a superfluous List.reverse call in Random.list #575

Closed
wants to merge 1 commit into
base: master
from

Conversation

Projects
None yet
2 participants
@jvoigtlaender
Contributor

jvoigtlaender commented Apr 28, 2016

Replaces https://github.com/elm-lang/core/pull/522, which became collateral damage in the branch killing spree.

Why remove that List.reverse call? Without it, generation is more efficient. And its presence or absence doesn't carry meaning for the semantics of randomness.

An argument has been made in the other discussion that with that call one has some sort of stability. But I have pointed out that it's a very fragile stability, and might even be harmful in terms of raising expectations, and in any case isn't compositional.

In this:

import Random
import Html

seed =
  Random.initialSeed 314159

triple n =
  let list = Random.list n (Random.int 0 100)
      gen = Random.map3 (,,) list Random.bool list
  in Random.step gen seed |> fst

main =
  Html.text <| toString (triple 2) ++ " " ++ toString (triple 5)

the outputs are ([2,22],True,[50,42]) vs. ([2,22,89,50,42],False,[47,79,82,79,6]). So only an appearance of stability.

@evancz evancz referenced this pull request Sep 22, 2016

Closed

Random #724

@evancz

This comment has been minimized.

Show comment
Hide comment
@evancz

evancz Sep 22, 2016

Member

Added to #724

Member

evancz commented Sep 22, 2016

Added to #724

@evancz evancz closed this Sep 22, 2016

@jvoigtlaender jvoigtlaender deleted the jvoigtlaender:random-reverse branch Sep 22, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment