cryptosense / ppx_factory

OCaml preprocessor to derive factory methods and default values from type definitions
BSD 2-Clause "Simplified" License
15 stars 1 forks source link

Make `default` a thunk? #22

Open bbc2 opened 5 years ago

bbc2 commented 5 years ago

The fact that default is a value makes it static. In some cases, like generating random values and incrementing IDs, it would be practical to customize default so that it can return a different value for a given factory function (I guess it could even be the default behavior, but it's not my issue here).

This can be worked around by creating factory functions manually but I think this defeats the purpose of this PPX.

So, would it make sense to be able to define default as function?

let default () =
  ...
leamingrad commented 5 years ago

That sounds sensible to me, I would be in favour of this change