holgerbrandl / kalasim

Discrete Event Simulator
https://www.kalasim.org/
MIT License
68 stars 10 forks source link

Optionally disallow use of untyped duration when tick-transform is defined #49

Closed holgerbrandl closed 1 year ago

holgerbrandl commented 2 years ago

When a user has defined a tick-transform in a model it should optionally support disallowing untyped use of hold etc.

sim.tickTransform = TickTransform(TimeUnit.MINUTES)
sim.enforceTypedDurations = true
...
hold(3) // should fail because possible incorrect/unintenional use of wrong unit
hold(3.minutes) // should work

In a second iteration, kalasim may also want to enforce a tick-unit when creating a simulation (i.e. val sim = Environment(TimeUnit.MINUTES)). This would make hold(2) impossible: The user would always need to state her intent about the duration by providing a tick-unit.

FYI @MohidQaiser

holgerbrandl commented 2 years ago

This would be a great improvement of the API, but it would currently block the use of kalasim in jupyter because of https://github.com/Kotlin/kotlin-jupyter/issues/351

holgerbrandl commented 2 years ago

It's not possible to separate the sub-tasks, as this would require to internalize the main implementation of Component.hold() in https://github.com/holgerbrandl/kalasim/blob/01070aad938ab2cdd0967932848d17499f7819c0/src/main/kotlin/org/kalasim/Component.kt#L1285-L1302

So the fix needs to be stalled until the duration API support has been fixed upstream.

holgerbrandl commented 1 year ago

Fixed in v0.9 by marking non-typed usage as experimental. See https://www.kalasim.org/changes/#v09