stedolan / crowbar

Property fuzzing for OCaml
MIT License
180 stars 31 forks source link

add a Syntax module #68

Closed zapashcanon closed 1 year ago

zapashcanon commented 1 year ago

Hi @stedolan,

I simply defined let* as dynamic_bind and let+ as map. They're in a Syntax module to avoid potential conflicts.

I use them a lot as it sometimes makes the code much more easy to follow and I guess I'm not the only one.

stedolan commented 1 year ago

Do you have an example of how they're used? I'm not following how let+ works from the source.

zapashcanon commented 1 year ago

Sure ! You can have a look at the fuzzer being written by my intern for our Wasm interpreter.

stedolan commented 1 year ago

Ah, I see - I couldn't understand how let+ would support multiple arguments to map, but it looks like you're always using it with just a single argument. Maybe it's simpler to specialise it to that case, and avoid having to write the square brackets each time?

You could also add a and+ using pair, I think.

zapashcanon commented 1 year ago

Indeed, I tried and it allows to use let-punning, making the code a little bit shorter. I'll update the PR. :)

I also added and+.

stedolan commented 1 year ago

Looks good! Could you add code examples to the doc comments of let+ and and*? (It's not necessarily obvious how to use these for people unfamiliar with the desugaring of let-operators)

zapashcanon commented 1 year ago

I added small examples. I'm not completely sure if they'll be useful enough for someone not familiar with this kind of de-sugaring. If you have a better idea I'll update the PR.

stedolan commented 1 year ago

Thanks!