5 ms·
Your example is very different. It seems you're still describing a pure API: testing those new function implementations can be done with the same test suite use
by thu 11y ago
Your example is very different. It seems you're still describing a pure API: testing those new function implementations can be done with the same test suite used for the slower variants.
In the blog post the author choose to specify that the observable behaviour is not pure.
- Veedrac 11y agoWhat if the cache involves IO? The behaviour is then assuredly not pure.
- asQuirreL 11y agoWhat sort of a cache would use IO? Not any cache I've heard of. (Genuinely interested)
- fyolnish 11y agoA cache too big to fit in memory
- Agathos 11y agoAny cache that is provided by an external process, or even by a remote machine, such as memcached.
- asQuirreL 11y agoI guess I should clarify and say "What sort of a cache would use IO and make a pure function impure?". Even if the cache is so large that it doesn't fit in memory, its behaviour would still be referentially transparent.
- Veedrac 11y agoThat's only if you don't count the IO itself as a side-effect. Does a language like Haskell give you the choice? If so,would it be idiomatic?
- peterfirefly 11y agoOne you want to keep around between invocations of the program?
- yummyfajitas 11y agoWhen you do this, the type system should reflect the fact that function has changed it's signature from `A => B` to `A => MaybeDoesntReturnOrHasLatency[B]`. Then the compiler will force downstream clients to take this into account, preventing weird hard to debug errors later on.
- Veedrac 11y agoFWIW, I'm not arguing about should or shouldn't - I'm just strengthening the original argument. That said, I don't think small bounded latency is a good thing to encode in a typesystem, much as I don't think runtimes should be encoded in a typesystem. It gives too much inflexibility for too little gain.
- SamReidHughes 11y agoI have wanted small bounded latency to be encoded before. (I'd also want the ability to ignore that information in most other programs I worked on. With the right sort of type system, you don't have inflexibility.)
- millstone 11y agoDid he? The author specified that the function "behaves differently;" to my reading this doesn't require that it be impure. A memoized function behaves differently than the underlying function (with observable consequences, like performance), but still obeys referential transparency, etc.