Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do record updates behave internally?

Tags:

haskell

data Thing = Thing {a :: Int, b :: Int, c :: Int, (...) , z :: Int} deriving Show

foo = Thing 1 2 3 4 5 (...) 26
mkBar x = x { c = 30 }

main = do print $ mkBar foo

What is copied over when I mutate foo in this way? As opposed to mutating part of a structure directly.

Data Thing = Thing {a :: IORef Int, b :: IORef Int, (...) , z :: IORef Int}
instance Show Thing where
(...something something unsafePerformIO...)

mkFoo = do a <- newIORef 1
           (...)
           z <- newIORef 26
           return Thing a b (...) z
mkBar x = writeIORef (c x) 30

main = do foo <- mkFoo
          mkBar foo
          print foo

Does compiling with optimizations change this behavior?

like image 407
redxaxder Avatar asked Nov 30 '11 15:11

redxaxder


People also ask

What is internal DNS and external DNS?

If you mean Internal as the DNS that may provide you firewall, it is your own DNS that is resolving (or forwarding requests) in your internal LAN. On the other side, the external DNS is the public DNS that resolves the domain request from internet.

What is needed to perform secure dynamic updates?

Only clients joined to the domain and with a valid Kerberos ticket can perform Secure DDNS updates. If a DHCP server is to perform this task, it must be a member of the DNS Proxy group.

How do DNS servers get updated?

In order to synchronize the DNS information, the Secondary servers will periodically check with the Primary server to see if there have been any changes in the data hosted there. If they detect a change, they will pull down the update.


1 Answers

In the first example, the pointers to the unchanged Int components are copied (and the constructor tag, if you wish to say so). It doesn't make much difference whether an Int or a pointer to one is copied, but if the components were large structures, it would.

Since the fields are not strict, the behaviour is, afaik, independent of optimisation. If the fields were strict, with optimisations, they might be unpacked into the constructor and then the raw Int# values would be copied.

In the second example, nothing is copied, the contents of the IORef are overwritten.

like image 116
Daniel Fischer Avatar answered Sep 21 '22 09:09

Daniel Fischer