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