Efficiency of using field labels vs pattern matching

Bulat Ziganshin bulat.ziganshin at gmail.com
Sun Aug 20 09:43:01 EDT 2006


Hello Brian,

Sunday, August 20, 2006, 5:15:41 PM, you wrote:

>     data R = R {_xRef :: !(IORef Int)}

>     foo :: Int -> R -> IO ()
>     foo i R{_xRef = xRef} = writeIORef xRef i

> is the above more efficient than:

>     foo i r = writeIORef (_xRef r) i

i think that first _may_ be more efficient because of strictness
analysis. btw, if you want beter efficiency, you may use unboxed
references (http://haskell.org/haskellwiki/Library/ArrayRef)




-- 
Best regards,
 Bulat                            mailto:Bulat.Ziganshin at gmail.com



More information about the Glasgow-haskell-users mailing list