<mrvn>
baader: you define a record that contains a type, but also you define an offset into that record named x that points to the data.
<mrvn>
baader: that way you can later use foo.x
<baader>
ok
<baader>
in a record definition w/ only 1 element tho, do i still explicitly have to use foo.x ?
<sam>
yes
<baader>
ok
<sam>
if you have a record of one element just for mutability, you'd likely want to use reference cells instead
<baader>
what would those look like ?
<baader>
i'm not exactly sure what you mean
<sam>
"let foo = ref 0;;" "!foo" to access the value, and "foo := 10" to set the value..
<baader>
say foo itsself was mutable, how would i change what the reference refers to ?
<baader>
ie. i want to let foo 'point' somewhere else ?
<sam>
"foo := 10"
<baader>
i thought that just changes the value foo refers to ?
<sam>
it changes the reference (however as the type is int, and ints are passed by value, there's no distinction in this case)
foxster has joined #ocaml
<baader>
i see
<sam>
references are just syntactic sugar for a single fielded mutable record (with the field name 'contents').. so "ref 0" would call a function such as "let ref v = { contents = v }"..
<sam>
"!foo" would be semantically equal to "foo.contents", and "foo := 10" would be equal to "foo.contents <- 10"
<baader>
yes, ok
baader has quit ["I'll be back"]
<mrvn>
There is a small difference between references and mutable fields though.
<mrvn>
A reference has an extra pointer and canbe passed as argument.
baader has joined #ocaml
<baader>
my 1st attempts of ocaml code look like shit
<sam>
mrvn: a reference _is_ a record with one mutable field. there is no difference
<sam>
..that is, an ocaml reference cell _is_... to correct my sloppy use or terms
<baader>
the i'reilly book has a section about references and their notation and its explained there, i just looked it up
<baader>
o'reilly even
<sam>
hmm, or then again.. looks like i'm wrong
<sam>
maybe
<baader>
type 'a ref = {mutable contents:'a}
<baader>
this is what the book says a reference really is
<mrvn>
baader: which is a box for the record and a pointer to a 'a. Bigger than a mutable alone.
<baader>
hm
<mrvn>
Its more an argument for that mutable are not refs.
<baader>
mutable marks something only as 'modifyable', right ?
<sam>
noone compares refs and mutable fields, but refs and records with a mutable field
<mrvn>
The mutable is only used in the compiler and needs no extra space. The ref needs an extra record wrping it.
<sam>
s/s/d/
<mrvn>
yeah, sorry, a bit OT.
<baader>
not OT, everything that gives me more insight into the language is very valuable to me, thx
<mrvn>
ref probably realy gets translated to the same as a record with one mutable if its not implemented that way anyway.
<sam>
ref is implemented that way
sam has quit ["Client exiting"]
brwill|out is now known as brwill
polin8 has quit [Read error: 110 (Connection timed out)]
foxster has quit [Client Quit]
foxster has joined #ocaml
palomer has quit [orwell.freenode.net irc.freenode.net]
palomer has joined #ocaml
lam_ has joined #ocaml
lam has quit [Read error: 60 (Operation timed out)]
foxen has joined #ocaml
foxster has quit [Client Quit]
lam_ has quit ["leaving"]
themus has quit ["Client Exiting"]
themus has joined #ocaml
lam has joined #ocaml
baader has quit ["I'll be back"]
bpdp has joined #ocaml
bpdp has left #ocaml []
foxen has quit [Client Quit]
CybeRDukE has joined #ocaml
CybeRDukE has quit ["Error #152 - Windows not found: (C)heer (P)arty (D)ance."]
docelic has joined #ocaml
systems has joined #ocaml
docelic has quit [Client Quit]
systems has left #ocaml []
phubuh has joined #ocaml
foxster has joined #ocaml
rzoz_ has joined #ocaml
ragzter has joined #ocaml
lam_ has joined #ocaml
foxster has quit [Client Quit]
lam has quit [Read error: 60 (Operation timed out)]
taw has quit [Remote closed the connection]
docelic has joined #ocaml
palomer has quit [orwell.freenode.net irc.freenode.net]
docelic has quit ["later"]
foxster has joined #ocaml
systems has joined #ocaml
owll has joined #ocaml
systems has quit [Read error: 110 (Connection timed out)]
systems has joined #ocaml
owll has quit ["Client Exiting"]
mrvn_ has joined #ocaml
mrvn has quit [Read error: 110 (Connection timed out)]
systems has quit ["Client Exiting"]
mrvn_ is now known as mrvn
brwill has quit [Read error: 60 (Operation timed out)]
palomer has joined #ocaml
mattam has joined #ocaml
CybeRDukE has joined #ocaml
ragzter has quit ["i hate c++"]
baader has joined #ocaml
<baader>
hello
docelic has joined #ocaml
phubuh has quit [Remote closed the connection]
phubuh has joined #ocaml
cm has joined #ocaml
phubuh has quit [Remote closed the connection]
phubuh has joined #ocaml
phubuh_ has joined #ocaml
phubuh has quit [Read error: 104 (Connection reset by peer)]
phubuh has joined #ocaml
phubuh_ has quit [Read error: 104 (Connection reset by peer)]
phubuh has quit [Read error: 104 (Connection reset by peer)]
phubuh has joined #ocaml
Kinners has joined #ocaml
karryall has joined #ocaml
CybeRDukE has quit ["Documentation is like sex: when it is good, it is very, very good. And when it is bad, it is better than nothing."]
foxster has quit [Client Quit]
Kinners has left #ocaml []
rzoz_ has quit [Remote closed the connection]
baader has quit [Read error: 104 (Connection reset by peer)]