alan-turing-institute / whatwhat

A reimagining of nowwhat in OCaml
MIT License
0 stars 0 forks source link

Increase scheduling preview #7

Closed callummole closed 2 years ago

callummole commented 2 years ago

Closes #3, #4

Done:

@mhauru perhaps Forecast.getTheCurrentSchedule should take a daysAhead argument, that defaults to 180 days, instead of being hardcoded?

callummole commented 2 years ago

There is an interesting wrinkle to optional arguments in ocaml. Optional arguments cannot be the last argument. If it is, the ocaml compiler cannot decide whether 1) the absence of an argument means it should partially apply the function and wait for a future argument, or 2) the absence means use the default value.

This gives the following warning:

let f ?(x=1) = x+x;;
Error (warning 16 [unerasable-optional-argument]): this optional argument cannot be erased.

But you can do these two things:

let f ?(x=1) y = x + y;;
f y;;
- : int = 4
let f ?(x=1) () = x + x;;
f ();;
- : int = 2

So, we can either: 1) have an optional argument but with a unit argument to end, but means that one always needs to call the function with (). 2) have a non-optional days argument.

mhauru commented 2 years ago

The () in each call sounds clunky, the kind of thing you never remember when you need to. I wouldn't be offended if it wasn't optional.