ayrnieu changed the topic of #ocaml to: OCaml 3.08.4 available! Archive of Caml Weekly News: http://sardes.inrialpes.fr/~aschmitt/cwn/ | A free book: http://cristal.inria.fr/~remy/cours/appsem/ | Mailing List: http://caml.inria.fr/bin/wilma/caml-list/ | Cookbook: http://pleac.sourceforge.net/
gim_ is now known as gim
mwc has quit [Read error: 110 (Connection timed out)]
threeve has joined #ocaml
batdog is now known as batdog|gone
SmerdyOffice has quit ["home"]
Smerdyakov has joined #ocaml
smimou has quit ["?"]
bzzbzz has joined #ocaml
mwc has joined #ocaml
<mwc> I have a question about the run time's storage for ints. I know it uses one bit to mask pointers. So how does it do this efficiently without creating a lot of overhead. I don't really care about the bit, more what seems to me to be extra bit shifting functions that would add up on sufficiently cache-local integer work
<Smerdyakov> I think it does just the operations you would expect it to.
<mwc> Hmm, I should probably find a good test case to be sure anyways
<mwc> but boxing scares me
mwc has left #ocaml []
batdog|gone is now known as batdog
mrsolo has quit [Read error: 104 (Connection reset by peer)]
descender has quit [Remote closed the connection]
descender has joined #ocaml
pango__ has joined #ocaml
pango_ has quit [Read error: 60 (Operation timed out)]
threeve has quit []
lus|wats has quit [""The law, in its majestic equality, forbids the rich as well as the poor to sleep under bridges, to beg in the streets, and t]
Schmurtz has quit [Read error: 113 (No route to host)]
Snark has joined #ocaml
Snark has quit [Read error: 104 (Connection reset by peer)]
__DL__ has joined #ocaml
Snark has joined #ocaml
Nutssh has joined #ocaml
pango__ is now known as pango
ski has joined #ocaml
<pango> ocaml does many operations directly on "boxed" ints (increment => add 2, etc.)
<pango> btw they're tagged rather than boxed
<pango> http://www.ocaml-tutorial.org/performance_and_profiling, "The representation of integers, tag bits, heap-allocated values"
Snark has quit [Read error: 104 (Connection reset by peer)]
Snark has joined #ocaml
Gueben has joined #ocaml
revision17_ has joined #ocaml
vodka-goo has joined #ocaml
revision17 has quit [Read error: 110 (Connection timed out)]
ski has quit ["foo"]
ski has joined #ocaml
ski_ has joined #ocaml
vodka-goo has quit []
faigo has joined #ocaml
ski has quit [Read error: 110 (Connection timed out)]
ski has joined #ocaml
kinners has joined #ocaml
ski_ has quit [Read error: 110 (Connection timed out)]
ski has quit ["later"]
kinners has quit ["leaving"]
smimou has joined #ocaml
malune has joined #ocaml
ulfdoz has joined #ocaml
<ulfdoz> Is there a nice project, using ocamlyacc/-lex? I need some advanced examples to have a look at.
<haakonn> aren't the canonical calculator examples advanced enough? :)
<haakonn> i found their treatment in the o'reilly book instructive
vodka-goo has joined #ocaml
<ulfdoz> haakonn: thx, I haven't recognized the chapters on first sight.
<haakonn> it's a thick book :)
<haakonn> also i used the ocaml manual to learn about them. i thought the example there wasn't very good, but the tools are described well
<ulfdoz> My biggest problems are in design and interoperability of lexer and parser. Sometimes I'm not sure, where to construct a value.
gim has quit [Read error: 110 (Connection timed out)]
vodka-goo has quit []
_JusSx_ has joined #ocaml
vezenchio has joined #ocaml
<Smerdyakov> ulfdoz, can you be more specific?
CLxyz has joined #ocaml
faigo has quit ["Leaving"]
_JusSx__ has joined #ocaml
vincenz has joined #ocaml
_JusSx_ has quit [Read error: 110 (Connection timed out)]
<ulfdoz> Smerdyakov: I try to. As I understand it, the lexer simply returns a token with each call. As there are several types of tokens, a natural way would be, to return the input simply word by word without any transformation in some dummy type Token of string, the parser gets this abstract token and has now to decide, whether it is a Bracket, a control struct or something similar or a string. The other way would be, to determine the special type of token
batdog is now known as batdog|gone
<Smerdyakov> Always determine the special type of the token. It makes your life much easier.
<Smerdyakov> Have a token constructor for each keyword, etc..
<ulfdoz> Am I right? This only works for context free grammars?
<Smerdyakov> In general, yacc only works for CFGs, yes.
<Smerdyakov> Well, that's not entirely true.
<Smerdyakov> You can do some processing in your rule bodies which allows more complicated language recognition.
<Smerdyakov> But this really isn't relevant to standard uses.
<ulfdoz> The application is sieve for the moment. Shouldn't be to hard, I hope.
batdog|gone is now known as batdog
batdog is now known as batdog|gone
threeve has joined #ocaml
threeve has quit [Client Quit]
threeve has joined #ocaml
batdog|gone is now known as batdog
ski has joined #ocaml
descender has quit [Remote closed the connection]
descender has joined #ocaml
Snark has quit ["Leaving"]
_JusSx_ has joined #ocaml
Smerdyakov has quit ["reboot"]
Banana has quit [Remote closed the connection]
Banana has joined #ocaml
_JusSx__ has quit [Read error: 110 (Connection timed out)]
Smerdyakov has joined #ocaml
revision17_ is now known as Revision17
Smerdyakov has quit ["reboot"]
Smerdyakov has joined #ocaml
sethk has joined #ocaml
<sethk> in the manual, core language, this syntax for type appears without being explained: type idref={mutable id: 'a. 'a -> 'a } Is that like a lambda syntax, \x.x? I understand 'a -> 'a; the function takes a value of some type and returns a value of the same type.
<sethk> but 'a. appears here with no explanation. I see that ocaml knows that a function is involved
<__DL__> it is a polymorphic field
<sethk> yes, I understand that
<sethk> but I don't see a reason for the first 'a in 'a. 'a -> 'a
<sethk> there is the type of the argument, 'a, and the type of the value returned, 'a
<__DL__> the first 'a mean : forall 'a the type is 'a -> 'a
<sethk> but what is the third 'a for?
<sethk> I can't see any situation where 'a -> 'a would appear where it would not be for all 'a
<__DL__> it is too make the diference with type 'a idref = {mutable id: 'a -> 'a }
<sethk> ok, which means what?
<sethk> what is different?
<sethk> I see no restriction on 'a in your example
<__DL__> in your example, something of type idref must contain a function that must accept an argument of anytype
<Smerdyakov> Consider these two functions:
<Smerdyakov> let idPoly x = x
<__DL__> in my example, soemthing of type (for example) int idref must containt an int-> int function
<Smerdyakov> let idInt (x : int) = x
<Smerdyakov> This has type idref: {id = idPoly}
<__DL__> when something of type float idref must contain a float -> float function
<Smerdyakov> This has type int parametric_idref, but not idref: {id = idInt}
<sethk> ok, taking __DL__'s example, I still don't see where the 'a. 'a -> 'a would occur where a function that returned, say, int would not also take an argument of type int
<sethk> I'm not sure if that makes sense since I'm missing the point
<sethk> is there a second function involved, so that some function is assigned to id, and that function returns another function of, say, the type int -> int?
<__DL__> well, I need example.
<sethk> __DL__, not sure what you mean. The manual pops in with type idref = { mutable id: 'a. 'a -> 'a };; There is nothing else
<sethk> then they have a let like this: let r = { id = fun x -> x};;
<sethk> which ocaml then infers as the type: val r : idref = { id = <fun> }
<sethk> and I don't understand how to interpret that
<__DL__> just one example :
<__DL__> type poly_idref = {mutable id1: 'a. 'a -> 'a };;
<__DL__> let f x = x;;
<__DL__> { id1 = f };;
<__DL__> let g x = x + 10;;
<__DL__> { id1 = g };;
<__DL__> try this, and see what appen
<__DL__> then compare with
<sethk> O
<__DL__> type 'a param_idref = {mutable id2: 'a -> 'a };;
<sethk> I'm completely lost, because id1 is part of a _type_. How can I assign something to it?
<sethk> the type itself changes, and has a current value like a global variable?
<__DL__> id1 is the name of a field. { id1 = f } is an objacte of type poly_idref, where the field id1 contain f
<sethk> I don't see how you create an object by declaring a type
<__DL__> s/objacte/value/
<__DL__> you don't
<sethk> ok, then I don't see how you create a value by declaring a type. :)
<__DL__> you create a new kind of value, and { id1 = f } is just one of those value
<sethk> I haven't used let. The only appearance of id1 anywhere is within your type statement.
<sethk> so what is f being assigned to?
<__DL__> type t = { a : int } create a new record type
<__DL__> having one field, a of type int
<sethk> it seems like by declaring the type, you've created a persistent thing, with a global name, that can be assigned to creating a current value of a type
<__DL__> No no, no
<__DL__> you create a new kind of value
<sethk> where? what value?
<__DL__> when you wrote { id1 = f };; then { id1 = g };; you try to create two different value of type poly_idref
<__DL__> but both id1 are different, each in a different poly_idref record
<sethk> when I enter your {id1 = f };;, ocaml says: - : poly_idref = {id1 = <fun>}
<__DL__> that mean that the expresion "{id1 = f }" have type poly_idref and value {id1 = <fun>} (where <fun> mean that this is a function that can't be printed)
<sethk> but that value isn't preserved anywhere
<__DL__> yes
<sethk> the only way to reference it is poly_idref
<__DL__> it is just an example to show you that when you wrote { id1 = g } caml will complain
<sethk> so I've changed the meaning of poly_idref until I decide to do another { id1 = something } ?
<__DL__> no, it is lost. It is just an example. The value have been created, and is imediatly lost scince I dont put it into a variable
<sethk> well, ok, but that doesn't tell me how I would actually use something like this.
<sethk> I could create a value? I could say let z = {id1 = f};; ?
<__DL__> yes
<__DL__> then you could wrote z.id1 to have the function in the id1 field of z
Gueben has quit [Read error: 104 (Connection reset by peer)]
<sethk> so that means that I've created the equivalent of a global variable, id1, and when I reference id1 I change poly_idref
<__DL__> NOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO
<sethk> well, I never typed poly_idref, did I? I only typed id1
<sethk> let z = { id1 = f } ;;
<sethk> val z : poly_idref = {id1 = <fun>}
<__DL__> ok, I see
<__DL__> ocaml is intelligent, it know that id1 is a field of the poly_idref type
<__DL__> and find (alone) that you want to refer to this type
<__DL__> in C you would have, to do the same, to wrote the type
<sethk> what if I create another type and use the name id1 again?
<__DL__> Then, you will have a problem
<__DL__> one should not have two record with the same field name in the same module
<__DL__> (but you could do it if you put them in different module (say file for a starter))
<sethk> obviously. So I've got a global variable, and if I use it again, I create ambiguity which ocaml doesn't flag.
<__DL__> it is not a global variable, and there isn't realy an ambiguity : ocaml use the last declared one
<sethk> the line: z = { id1 = f };; does not stand alone, it depends on the most recent reference to id1
<__DL__> the most recent type declaration with such field
<sethk> ok, I guess I can't use that feature and preserve the usual protections you would expect in a functional language. Since mutable is imperative, I guess that's to be expected
<__DL__> note that let z = { id1 =f };; let y = { id1 = g };; will create two value with no conection betwen them
<sethk> yes, I see that, but you still are unprotected from using the same name twice, which would absolutely happen in code of real life complexity. Even a C compiler can generate a warning about that.
<__DL__> well, an module should ba of a reasonable size, and there is no problem.
<__DL__> I still have the impression that you missunderstood me.
<__DL__> if you do :
<__DL__> let z = { id1 =f };;
<__DL__> then
<sethk> no, I understand, I'm just surprised that such a name clash wouldn't be flagged. Maybe a non-interactive compile would flag it.
<__DL__> let y = { id1 = g };;
<__DL__> maybe, i don't remeber
<__DL__> note that the toplevel is to be seen as a developer tool to make some test
<__DL__> not as an end user thing
<__DL__> (well, it is also usefull to learn and teach ocaml)
<sethk> yes, I understand that. The book talks about doing ocaml -c, but I just tried that and it doesn't work. Maybe the compiler has a different name.
<__DL__> it is ocamlc -c, not ocaml -c
<sethk> yes, I see that. The book doesn't.
<__DL__> which book ?
<sethk> an on line thing. It's a misprint; ocamlc appears later in the same page
<sethk> no warning, though.
<__DL__> well, you will have error when you use them
<sethk> ok, I'll have to try that
<sethk> the docs I've read so far are quite good, except in a few places they do something out of left field and don't explain it.
<sethk> I see what they are doing. They are giving you a way to hack around the fact that the compiler can't infer a particular type of polymorphism. Possibly the fourth page of the introduction is not the best place to do that. :)
_JusSx__ has joined #ocaml
<__DL__> yes, it is not the simpleur things in ocaml...
<sethk> it's kind of subtle if you are just starting to figure out how types work in the first place
_JusSx_ has quit [Read error: 110 (Connection timed out)]
_DL_ has joined #ocaml
_DL_ has quit [Read error: 104 (Connection reset by peer)]
Gueben has joined #ocaml
_JusSx__ has quit ["leaving"]
__DL__ has quit ["Bye Bye"]
Gueben has quit [Remote closed the connection]