GithubHelp home page GithubHelp logo

Comments (4)

mgold avatar mgold commented on August 17, 2024

The defintion of a producer is intentionally exported. You need a random generator and a shrinker.

The generator you should be able to do with Random.Extra.frequency, combining generators for each tag. (Be sure to bump to version 1.0.1 of that library; we fixed a bug with that function.) The shrinker will likely involve doing a case analysis on each tag and saying how to shrink it. You'll need to look at the shrink library for that.

If you come up with a good reusable abstraction, let me know. But my hunch is that you have to make this producer yourself.

from elm-check.

avh4 avatar avh4 commented on August 17, 2024

There should be something like

oneOf : List (Producer a) -> Producer a

that gives equal frequency to each option. choice might be another possible name for it.

from elm-check.

mgold avatar mgold commented on August 17, 2024

That's a possibility, but I don't think it will help with union types. Each producer in the list will presumably include a generator for one tag, but the shrinker must shrink all tags. So you have a few choices:

  • Define the shrinker once, and use it to create N producers. It seems simpler to create the generator and add the shrinker once at the end.
  • With each producer, define a shrinker that shrinks only that tag. This means you repeat _ -> Shrink.noShrink N times, and N case statements aren't a small amount of code. It seems simpler to put all the branches next to each other in one function. But if you go this route, the implementation has two choices:
    • When shrinking, pick only one shrinker. Odds are 1/N that you'll pick the one that shrinks the tag you have. Ick.
    • Use all the shrinkers and concatenate their lists of values. Sensible, but not oneOf the producers -> use choice, but above objection still applies.

I think these issues would become obvious to anyone if they tried to actually code it up. That's why I asked to see code: abstractions should be extracted from something that works, not plucked out of thin air.

All that being said, oneOf isn't a bad idea for generators (even though it's less general than frequency), but shrinkers work in the opposite direction, so it falls apart.

from elm-check.

mgold avatar mgold commented on August 17, 2024

Action item: document the above.

from elm-check.

Related Issues (4)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.