
Hello everyone, I was coming from a C++ background and I always wondered if there is a distinction between pass-by-value and pass-by-reference in Haskell (or pass-by-thunk? since an argument might be partially evaluated due to laziness in Haskell). Is there a way to guarantee that an function argument is passed in an efficient manner? For example, if we have a data type data Document = Document { title :: Text , author :: Name , content :: Text -- and potentially many more } doc = Document {..} -- omitted and we want to pass doc to a function, we should ideally hope that doc is not getting duplicated when passing it as an argument. Another example might be the Reader monad, where we are passing possibly the same environment to multiple functions. In C++, we could either pass by a pointer or a reference, but I'm not sure what the best practices are in Haskell. The most relevant construct in Haskell seems to be IORef, though I'm not sure if this is the correct way to use it. For exmaple, if I want to pre-load a template document on disk as Text or ByteString into the memory when the program starts, should I put it in a IORef and pass it into (more than one) functions or should I pass it into the function directly? Should I worry about this at all? This question might be related to the implementation of the ghc compiler. It would be better if anyone could shed some lights on the implementation details. Thank you, Kram