<Smerdyakov>
Learn about the value restriction and it should be clear.
<mikeX>
what do you mean? I've used 'a. in other cases, but it causes a syntax error here.
<Smerdyakov>
OCaml has most general type unifications.
<Smerdyakov>
Adding a type annotation will never give something a more general type.
<Smerdyakov>
(So your last line in this channel is irrelevant to the issue.)
<mikeX>
hmm, I'm not sure I follow you
<Smerdyakov>
So you've probably never heard of the value restriction?
<mikeX>
I guess not
<Smerdyakov>
Then maybe you should have looked for it instead of concluding that my advice was irrelevant. ;)
<Smerdyakov>
Let me see if OCaml uses that terminology... "value restriction" is from the SML Definition.
<mikeX>
I didn't come to such a conclusion
<mikeX>
I just thought it had to do with this: file:///usr/share/doc/ocaml-doc/ocaml.html/manual005.html#ss:polymorphic-methods
<mikeX>
(even though the object system is not involved here)
<Smerdyakov>
Well, I couldn't quickly find an appropriate section of the OCaml manual.
<zvrba>
it's described in that short ocaml tutorial
<mikeX>
what would that be zvrba ?
<zvrba>
value restriction
<mikeX>
No I mean the short tutorial
<zvrba>
jason hickey's
<mikeX>
hm, I'll take a look, thanks
<Smerdyakov>
It _must_ be in the manual somewhere!
<mikeX>
well I was somehow aware of this, but not how to solve it in such a case
<Smerdyakov>
I don't think the problem is related to anything having to do with the object system.
<mikeX>
cause I *should* be able to work around this somehow right?
<Smerdyakov>
Yes. It's easy.
<Smerdyakov>
The value restriction just says that a `let' binding for an expression of polymorphic type only works with an expression that is a _value_.
<Smerdyakov>
In particular, a `let' expression is not a value.
<mikeX>
sorry I can't understand you
<Smerdyakov>
If your program contains the declaration:
<Smerdyakov>
let x = e;
<Smerdyakov>
Where you want `x' to end up with a polymorphic type
<Smerdyakov>
Then `e` must be a value.
<Smerdyakov>
No `let' expression is a value.
mnemonic_ has joined #ocaml
mnemonic_ has quit [Client Quit]
<mikeX>
right, so the 'let code = ref []' is causing a problem
<mikeX>
correct?
<Smerdyakov>
Yes
<mikeX>
ok, but I still don't see how I could make it work (and keep the closure)
<Smerdyakov>
That's surprising.
<Smerdyakov>
I never said you'd be able to do it all within a single `let' declaration.
<mikeX>
meaning?
<Smerdyakov>
For crying out loud.
<Smerdyakov>
Use a separate declaration for the reference.
<mikeX>
so I can't keep the closure
<Smerdyakov>
That would not change anything related to a closure.
<mikeX>
well, can you give me an example of what you mean? cause I don't see it that way
<mikeX>
yes technically it wouldn't but I wan't 'code' to be 'hidden'
<mikeX>
i.e. not visible from outside the function
finelemon has quit [Read error: 113 (No route to host)]
<Smerdyakov>
I would use the 'local' declaration for that in SML. I don't know if OCaml has an equivalent.
<Smerdyakov>
You can always add an extra unit argument to the function, and then rebind the same name to its own application afterward.
<mikeX>
hmm, I see, thanks
finelemon has joined #ocaml
<zvrba>
so, risking to start a holy war
<mikeX>
sml vs ocaml?
<zvrba>
which is "better" - SML or Ocaml?
<zvrba>
yeah :)
<mikeX>
hehe
<Smerdyakov>
I strongly prefer SML.
<zvrba>
why?
<Smerdyakov>
Much cleaner language design.
<zvrba>
uh yeah, i guess no object layer patched ontop :)
<Smerdyakov>
Much cleaner even if you ignore the OCaml OO part
<zvrba>
Smerdyakov: any good sml implementation.. open-source + debugger?
<Smerdyakov>
I mean, come on, printf and scanf format strings are built into the OCaml language.
<zvrba>
(i've seen like MLTon generates fast code, etc... but they don't have a debugger >:)
mnemonic_ has joined #ocaml
<Smerdyakov>
zvrba, you don't need a debugger if you have a repl, and everyone but MLton has that.
<zvrba>
Smerdyakov: uf yeah, ugly hack. i froze when i saw their types
<zvrba>
Smerdyakov: true :)
mnemonic has quit [Read error: 110 (Connection timed out)]
mnemonic_ has quit [Client Quit]
mnemonic has joined #ocaml
<mnemonic>
re
chessguy has joined #ocaml
mnemonic_ has joined #ocaml
mnemonic_ has quit [Client Quit]
mnemonic has quit [Read error: 104 (Connection reset by peer)]