4 ms·
Yes, you pass in Random, and file streams. If you need to pass the same set of multiple things to multiple functions, you declare a type that represents all th
by Peaker 14y ago
Yes, you pass in Random, and file streams.
If you need to pass the same set of multiple things to multiple functions, you declare a type that represents all these arguments. At least this is the approach used in Haskell, with semi-explicit (explicit in type, implicit in the value) passing of parameters.
If you take a time argument, you have to declare an extra argument, not an extra variable, and in a powerful language, you can abstract its passing around.
If you move the method to a new location where its input is not available, you propagate up the input requirement in the form of argument passing, which conveys the new dependency up the call chain.
- adamauckland 14y ago> If you need to pass the same set of multiple things to multiple functions, you declare a type that represents all these arguments. At least this is the approach used in Haskell, with semi-explicit (explicit in type, implicit in the value) passing of parameters. So might one call this a Context object?
- jerf 14y agoIn Haskell, they call this a Reader. This parallels the Writer, which lets code just 'write' to the provided values but not use them (more useful than it sounds, for instance, logging). But it is basically a context value, yes.
- Peaker 14y agoWell, the nice thing about this abstraction in Haskell, is that you can give a name to the notion of receiving a bunch of values (Reader), outputting a bunch of values (Writer), threading state that can be both Read and Written (State), non-determinism (List), etc. You can thus compose all these behaviors you want into a single type constructor and build your programs as composites of this type.