How can a time function exist in functional programming?

Yes and no.

Different functional programming languages solve them differently.

In Haskell (a very pure one) all this stuff has to happen in something called the I/O Monad – see here.

You can think of it as getting another input (and output) into your function (the world-state) or easier as a place where “impureness” like getting the changing time happens.

Other languages like F# just have some impureness built in and so you can have a function that returns different values for the same input – just like normal imperative languages.

As Jeffrey Burka mentioned in his comment:
Here is the nice introduction to the I/O Monad straight from the Haskell wiki.

Leave a Comment