<losira>
you could probably start with the normal syntax and replace it with parts from the revised syntax
<hooman>
ah interesting.. there are also built in tools for converting back and forth as well
spew has joined #ocaml
losira has left #ocaml [#ocaml]
ziyourenxiang has joined #ocaml
FreeBirdLjj has joined #ocaml
cobreadmonster has quit [Quit: Connection closed for inactivity]
infinity0_ has joined #ocaml
infinity0_ has quit [Changing host]
infinity0_ has joined #ocaml
infinity0 is now known as Guest29715
Guest29715 has quit [Ping timeout: 268 seconds]
spew has quit [Ping timeout: 248 seconds]
spew has joined #ocaml
spew has quit [Read error: Connection reset by peer]
malina has quit [Quit: Throwing apples of Montserrat]
cbot_ has quit [Quit: Leaving]
am2904 has joined #ocaml
FreeBirdLjj has quit [Remote host closed the connection]
FreeBirdLjj has joined #ocaml
FreeBirdLjj has quit [Remote host closed the connection]
slash^ has joined #ocaml
kerrhau has quit [Ping timeout: 268 seconds]
malc_ has joined #ocaml
argent_smith has joined #ocaml
enterprisey has quit [Remote host closed the connection]
argent_smith has quit [Quit: Leaving.]
am2904 has quit [Quit: My Mac has gone to sleep. ZZZzzz…]
kakadu has joined #ocaml
jnavila has joined #ocaml
jnavila has quit [Ping timeout: 240 seconds]
jnavila has joined #ocaml
TarVanimelde has joined #ocaml
dmi3y has joined #ocaml
jnavila has quit [Ping timeout: 248 seconds]
jnavila has joined #ocaml
am2904 has joined #ocaml
am2904 has quit [Client Quit]
am2904 has joined #ocaml
dmi3y has quit [Quit: dmi3y]
Hetu has joined #ocaml
dmi3y has joined #ocaml
am2904 has quit [Quit: My Mac has gone to sleep. ZZZzzz…]
am2904 has joined #ocaml
am2904 has quit [Client Quit]
am2904 has joined #ocaml
am2904 has quit [Client Quit]
am2904 has joined #ocaml
am2904 has quit [Client Quit]
TarVanimelde has quit [Quit: TarVanimelde]
jnavila has quit [Ping timeout: 240 seconds]
dmi3y has quit [Quit: dmi3y]
ygrek_ has joined #ocaml
ome has quit [Quit: Connection closed for inactivity]
shinnya has quit [Ping timeout: 248 seconds]
demonimin has quit [Ping timeout: 248 seconds]
mfp has joined #ocaml
zolk3ri has joined #ocaml
demonimin has joined #ocaml
demonimin has joined #ocaml
silver has joined #ocaml
<Drup>
hooman: this is as much the future as a fallout video game.
FreeBirdLjj has joined #ocaml
jnavila has joined #ocaml
argent_smith has joined #ocaml
FreeBirdLjj has quit [Remote host closed the connection]
FreeBirdLjj has joined #ocaml
Anarchos has joined #ocaml
barcabuona has joined #ocaml
sgnb has quit [Ping timeout: 268 seconds]
nomicflux has joined #ocaml
Hetu has quit [Quit: Verlassend]
Anarchos has quit [Quit: Vision[0.10.2]: i've been blurred!]
ShalokShalom has joined #ocaml
Anarchos has joined #ocaml
jnavila has quit [Ping timeout: 240 seconds]
dmi3y has joined #ocaml
ygrek_ has quit [Ping timeout: 248 seconds]
argent_smith1 has joined #ocaml
argent_smith has quit [Ping timeout: 240 seconds]
FreeBirdLjj has quit [Remote host closed the connection]
barcabuona has quit [Quit: WeeChat 1.9.1]
wklm has joined #ocaml
spew has joined #ocaml
FreeBirdLjj has joined #ocaml
FreeBirdLjj has quit [Remote host closed the connection]
FreeBirdLjj has joined #ocaml
wklm has quit [Ping timeout: 248 seconds]
spew has quit [Read error: Connection reset by peer]
wklm has joined #ocaml
spew has joined #ocaml
chetshah has joined #ocaml
<chetshah>
Hi all, ocaml beginner here, was wondering that one cannot make a record without declaring its type first?
kolko has joined #ocaml
spew has quit [Ping timeout: 240 seconds]
<chetshah>
I was going through some programming languages lectures that use smlnj and it is allowed to make records before declaring type first. Where can I know more about this?
<Anarchos>
chetshah yes you can
<chetshah>
let k = { name="chet"; age=40 };; gives unbound record field name.
<chetshah>
if I have not declared a record type with fields name and age.
Anarchos has quit [Ping timeout: 268 seconds]
jmiven has quit [Quit: co'o]
jmiven has joined #ocaml
govg has quit [Ping timeout: 248 seconds]
jnavila has joined #ocaml
jbrown has joined #ocaml
sailorswift has joined #ocaml
sailorswift has quit [Remote host closed the connection]
<def`>
chetshah: in OCaml you have to predeclare records
<def`>
you can work around by using objects: let k = object method name = "chet" method age = 40 end;; but it is a bit more verbose :)
<chetshah>
def` got it! Thanks
barcabuona has joined #ocaml
dmi3y has quit [Quit: dmi3y]
FreeBirdLjj has quit [Remote host closed the connection]
FreeBirdLjj has joined #ocaml
Fistine has quit [Ping timeout: 255 seconds]
Fardale has quit [Ping timeout: 240 seconds]
Anarchos has joined #ocaml
tobiasBora has quit [Ping timeout: 264 seconds]
FreeBirdLjj has quit [Ping timeout: 260 seconds]
jbrown has quit [Ping timeout: 240 seconds]
Anarchos has quit [Ping timeout: 240 seconds]
wklm has quit [Ping timeout: 268 seconds]
chetshah has quit [Quit: Page closed]
sz0 has joined #ocaml
spew has joined #ocaml
barcabuona has quit [Quit: WeeChat 1.9.1]
argent_smith has joined #ocaml
argent_smith1 has quit [Ping timeout: 248 seconds]
jimt_ has joined #ocaml
jimt has quit [Ping timeout: 248 seconds]
nomicflux has quit [Quit: nomicflux]
zmt00 has joined #ocaml
spew has quit [Ping timeout: 240 seconds]
kerrhau has joined #ocaml
barcabuona has joined #ocaml
moei has quit [Read error: Connection reset by peer]
<lyxia>
andreas___: if it were allowed, you could write this: some_foo.f <- (fun x -> x + 1) ; some_foo.f "ocaml"; (where some_foo gets specialized as int foo then string foo)
spew has quit [Read error: Connection reset by peer]
<lyxia>
oh wait f is not mutable
<andreas___>
lyxia: yeah, only x is mutable and is not used in f..
<lyxia>
oh well, the value restriction is meant to prevent these kinds of cases I mentioned, and perhaps it's not worth the trouble to do it in a too fine grained way.
<andreas___>
That's a shame... though it seems like it's a silly example, I have some code quite like it :)
moei has quit [Read error: Connection reset by peer]
<malc_>
andreas___: curiously enough "x : string ref" is accepted
<andreas___>
malc_: hmm, I get the same error with string ref.
<andreas___>
on 4.04.2
<malc_>
4.06
<malc_>
type 'a foo = Foo : {
<malc_>
f : 'a -> int;
<malc_>
x : string ref;
<malc_>
} -> 'a foo
<malc_>
<malc_>
let some_foo = Foo {
<malc_>
f = (fun _ -> 1);
<malc_>
x = ref "";
<malc_>
}
<malc_>
;;
<malc_>
type 'a foo = Foo : { f : 'a -> int; x : string ref; } -> 'a foo
Anarchos has joined #ocaml
<malc_>
val some_foo : '_weak1 foo = Foo {f = <fun>; x = {contents = ""}}
<malc_>
<andreas___>
It looks like it's missing the forall-annotation on some_foo though: let some_foo : 'a. 'a foo = ...
<octachron>
malc_, the weakly polymrophic type variable `_weak1` shows that the value restriction has biten
<malc_>
octachron: original variant uses _weak4 whatever that means
<malc_>
uses === results in
<octachron>
however, it is indeed sort of possible to avoid the value restriction with a string ref: let x = ref ""; let foo = { f=(fun _ -> 1); x } works (for some values of "works")
<lyxia>
oh that's neat
<lyxia>
malc_: the point is not to get the underscore in front.
<octachron>
malc_, "_weak${n}" means the n-th weakly polymorphic type variable introduced in the typing environment
<malc_>
andreas___: yeah, fails with forall annotation
<octachron>
weakly polymorphic type variable are a form of "placeholder" types for a concrete but unknown at the moment type
<andreas___>
octachron: that workaround might actually do the trick in my case -- thanks! Trying it out now..
<lyxia>
malc_: try let Foo a = some_foo in a.f 0;; then ask for the type of some_foo again. "int foo".
wklm has joined #ocaml
<octachron>
andreas___, another option when tiptoeing around the value restriction is to hid the value behind a function call "let foo () = Foo …"
<andreas___>
octachron: thanks. Extracting to a separate let worked this time around. Can you explain why makes a difference?
<M-ErkkiSeppl>
andreas___: polymorphic values can be unsafe in the presence of mutation, and there's a simple syntactic method to ensure that the unsafe cases are impossible
<M-ErkkiSeppl>
in this case it's always safe to have a function return a polymorphic instance, because it creates a new one instead of referring to an old one
am2904 has joined #ocaml
<andreas___>
That makes sense. It refers to the "hiding behind function call"-workaround, right? How about the other workaround using a ref: `let x = ref ""; let foo = { f=(fun _ -> 1); x } `
AlexRussia has quit [Ping timeout: 240 seconds]
zolk3ri has joined #ocaml
AlexRussia has joined #ocaml
AlexRussia has quit [Client Quit]
am2904 has quit [Read error: Connection reset by peer]
clockish has quit [Ping timeout: 240 seconds]
clockish has joined #ocaml
Fardale has joined #ocaml
<octachron>
andreas___, basically the value restriction is syntactic by nature; it restricts polymorphism to value; with a restrictive definition of what is a value
<octachron>
in particular, a record with a mutable field is not considered as a value, neither is the result of a function call
<octachron>
so in `{ f = (fun _ -> 1); x = ref "" }` the value restriction sees a function call ref "", so no polymorphism allowed`
<octachron>
similarly with `{ f = (fun _ -> 1); x = { contents = ""} }`, contents is a mutable field, so still no polymorphism
TarVanimelde has joined #ocaml
<octachron>
but with `let x = ref "" let foo = { f=…; x }`, the first let defines a string ref; so the value restriction is not allowed
<octachron>
and in the second let, we are building a record with no mutable fiels , from two values f=(fun _ -> ), (functions are always considered a value)
<octachron>
and x, which is already constructed value; so the value restriction does not trigger
<octachron>
and the type of foo can be generalized safely
<octachron>
*a string ref, … so the value is not allowed → a string ref, so the value restriction is not problematic
<hooman>
hm thats a strange special case
argent_smith1 has joined #ocaml
argent_smith has quit [Ping timeout: 248 seconds]
jbrown has joined #ocaml
slash^ has quit [Read error: Connection reset by peer]
mengu has joined #ocaml
TarVanimelde has quit [Quit: TarVanimelde]
<octachron>
hooman, in which way is it a special case? It is more a consequence of application of very generic and broad rules that leads to a not so obvious consequence
<octachron>
and this is quite far from Banach-Tarski level of unintended consequence
sh0t has joined #ocaml
<hooman>
hm thats true
<andreas___>
octachron: thanks for the elaborate explanation. Any good sources for reading further up on this?