gl changed the topic of #ocaml to: Discussions about the OCaml programming language | http://caml.inria.fr/ | happy new year, dudes.
ikaros has joined #ocaml
lmbdwr_ is now known as lmbdwr
cjeris has left #ocaml []
Z4rd0Z has joined #ocaml
joshcryer has joined #ocaml
b00t has quit [No route to host]
postalchris has joined #ocaml
postalchris has left #ocaml []
b00t has joined #ocaml
ludwig- has quit ["Leaving"]
whatitdo has quit []
buluca has quit ["Leaving."]
bogdano has quit ["leaving"]
ocher has quit [Read error: 131 (Connection reset by peer)]
Mr_Awesome has joined #ocaml
zak__ has joined #ocaml
<zak__> how complete and fast are the gtk2 bindings? like, would it be suitable for something graphics intensive?
<Mr_Awesome> zak__: im guessing they would be comparable to straight gtk2
<zak__> Mr_Awesome: but i'm worried adding an extra layer might be a significant performance hit, if i'm calling a lot of rendering stuff
<Mr_Awesome> most likely not
<Mr_Awesome> the layer is rather thin
<Mr_Awesome> and ocaml isnt a bloated, inefficient language
<Mr_Awesome> if they were ruby bindings id be concerned
<Mr_Awesome> i cant give you complete assurity, but id say im most likely correct
pango has quit [Remote closed the connection]
pango has joined #ocaml
dblmit has joined #ocaml
<dblmit> there's no way to test for a function by name at run time is there? Like checking if a module contains a "foo" function?
<Smerdyakov> There's no way to do anything with modules at runtime..
Smerdyakov has quit ["Leaving"]
beschmi has quit ["Leaving"]
zak__ has quit ["Leaving"]
Mr_Awesome has quit ["...and the Awesome level drops"]
ramkrsna has joined #ocaml
batdog|gone has quit [Read error: 110 (Connection timed out)]
_velco has joined #ocaml
_velco is now known as chi11
chi11 is now known as chil1
chil1 has left #ocaml []
chi11 has joined #ocaml
whatthedeuce has joined #ocaml
pattern has quit [Read error: 110 (Connection timed out)]
love-pingoo has joined #ocaml
velco has joined #ocaml
whatthedeuce has left #ocaml []
pstickne has quit ["Leaving"]
pattern has joined #ocaml
slipstream-- has joined #ocaml
khaladan_ has joined #ocaml
slipstream has quit [Read error: 110 (Connection timed out)]
khaladan has quit [Connection timed out]
ikaros has quit [Read error: 60 (Operation timed out)]
ikaros has joined #ocaml
b00t has quit [Client Quit]
pmatos has joined #ocaml
<ulfdoz> Do I need a special handling for escaped characters in strings, when writing a lexer definition for ocamllex?
<flux-> hmm.. it doesn't automatically handle 'escaping', if that's what you are asking
<ulfdoz> A string would be a token like e.g. "foo bar"
<flux-> usually strings need to be handled separately in a lexer
<flux-> although strings like "foo (literal \t) bar" should be possible to handle without special cases
<flux-> it's things like " \" " that need special-casing
<flux-> here's a str rule I've used: str = parse | '"' { [] } | "\\\"" { '"'::(str lexbuf) } | '\\' (_ as ch) { match ch with | 'n' -> '\n'::(str lexbuf) | 't' -> '\t'::(str lexbuf) | 'r' -> '\r'::(str lexbuf) | ch -> '\\'::ch::(str lexbuf) } | '\n' { raise Eol } | _ as ch { ch::(str lexbuf) } - you will need to know you're parsing a string, of course, beforehand
<flux-> and it's not tail-recursive
<ulfdoz> let escaped_char = '\' ['
<ulfdoz> let char_not_dquote = ['
<ulfdoz> let string = '"' (char_not_dquote | escaped_char)* '"'
<flux-> I don't think that'll work
<ulfdoz> This I hope mathces, too. escaped_char = '\\' ['
<flux-> hm, actually
<flux-> it will work, but I'm not sure what you're attempting to do
<ulfdoz> whah, fscking NUL-Char.
<flux-> what is [' ?
<ulfdoz> Essentially I match everything from a double-quote until an unescaped double-quote.
<ulfdoz> flux-: That was intelligent readline interpreting \\x00 as NUL-Char. ;)
<flux-> so what should char_not_dquote look like?
<flux-> or escaped_char, for that matter, was it wrong too?
<flux-> is " \x22?
<flux-> apparently yes
<flux-> but yes, I can see that would work..
<flux-> if I'm not missing something obvious :-), I somehow thought it couldn't be that simple
<flux-> you might still need to 'decode' the escaping, though, but if escaped string is sufficient for your needs, why not
<flux-> doesn't that work?
<ulfdoz> For now, I don't think, that I'll have the need to process the string token. If I get problems with serializing the parse-tree, I still can introduce special rules, hopefully.
Z4rd0Z has quit []
dblmit has quit ["Leaving"]
pmatos has quit [Remote closed the connection]
Z4rd0Z has joined #ocaml
romanoffi has joined #ocaml
triple_ has joined #ocaml
Smerdyakov has joined #ocaml
<mellum> Does anybody know what this means: "Warning: Module type Map.S not found" when linking
fincher has joined #ocaml
<fincher> with polymorphic variants available, what's the advantage of using regular old sum types?
<mellum> Oh, actually it's not from linking, but from ocamldoc
<mellum> I think I'll not care then :)
<haelix> fincher: static safety
<haelix> and performance, too
<fincher> haelix: static safety? I thought polymorphic variants were safe. Do you have an example where they aren't?
<haelix> they are type safe
<haelix> it's just when doing pattern matching, that a runtime extensible set of cases can fall in the default '_' matching rule
<haelix> so it offers less static guarantees,
velco has quit [Read error: 104 (Connection reset by peer)]
triple_ has quit [Read error: 60 (Operation timed out)]
ikaros has quit ["Leaving"]
Aradorn has joined #ocaml
cjeris has joined #ocaml
<love-pingoo> fincher: it's not only about static guarantees.. polymorphic variants seem nice in simple examples
<love-pingoo> but they become much less natural with larger examples involving recursions, or when you start to need to specify :>t subtypings
batdog|gone has joined #ocaml
<fincher> haelix: how do polymorphic variants affect runtime performance?
oscarh has quit [zelazny.freenode.net irc.freenode.net]
Hadaka has quit [zelazny.freenode.net irc.freenode.net]
<haelix> Closest to the metal, I'd say that where normal variant pattern matchiing involves switch/casing on integers (well, symbol addresses)
<haelix> polymorphic variants incurs the overhead of a lookup in a string dictionnary
<haelix> (hash table, balanced tree, whatever associative)
<love-pingoo> I think the efficiency difference is not that important, but the ease of use matter more
<love-pingoo> +s
<haelix> love-pingoo: I agree with you for the efficiency
<haelix> but I'm unclear as to which side you place the ease of use
<haelix> on
<love-pingoo> I once thought that polymorphic variants would be in my dream language, replacing core variants..
<fincher> haelix: why would polymorphic variants require string lookup? Isn't the set of possible polymorphic variants fixed at compile time? Can't they be compiled to an integer like regular variants?
<love-pingoo> since then, I actually tried polymorphic variants and realized that many problems had to be overcome first
<love-pingoo> haelix: core variants are actually easier (clearer)
<fincher> haelix: wait, string comparisons would be necessary in the face of separate compilation.
<love-pingoo> fincher: it's not set at compile time because compilation is modular
<haelix> thx for clarifying
<haelix> love-pingoo fincher : perfect timing
<haelix> :)
<fincher> love-pingoo: core variants being regular algebraic datatype variants?
<haelix> I was still analysing the problem
<love-pingoo> fincher: yeah
<love-pingoo> with polymorphic variants there is too much to guess sometimes, so error messages get very obscure
ikaros has joined #ocaml
<fincher> love-pingoo: how advantageous in practice is the ability of polymorphic variants to do subtyping?
<love-pingoo> I used it only once.
<love-pingoo> Depends on the kind of code you write.
<love-pingoo> But the time I used it, I was disappointed cause I had to do tricks to allow recursive type definitions, and I had to explicit type coercions.
<love-pingoo> I actually plan to remove polymorphic variants from that piece of code..
<fincher> replacing them with what?
<love-pingoo> fincher: the only place I like to use them is when I have a simple datatype, but I'm too lazy to define it
<love-pingoo> e.g I have a class, it has a state, I don't bother about defining the possible cases for that state, I just use polymorphic variants
<Smerdyakov> ...and I would say that that kind of "lazyness" is never justified.
buluca has joined #ocaml
<Smerdyakov> And we should certainly be fair to the designers of polymorphic variants in saying that they were never meant to support "lazyness," but rather facilitate "extensible case analysis" and such.
<stevan> I was envisioning (and please correct me if I am misunderstanding the feature) using polymorphic variants as a kind of "cross module type" of sorts
<stevan> so that I would define the same polymorphic variant in several modules, and functions to use them, etc etc.
<stevan> but when I used the modules together, it would always seem to be the same type
<stevan> is that a gross abuse of the feature? is it not even possible (I havent actually tested my thoughts yet)?
<haelix> me too ! I have my question, too ! how is the exception type different from a polymorphic type ?
<Smerdyakov> I think it is an abuse. You should define the type in a single module.
<stevan> Smerdyakov: but what if its basically the same type?
<Smerdyakov> haelix, exception constructors need to be defined explicitly, and there is always a finite set of them at any execution point.
<Smerdyakov> haelix, polymorphic variant constructors can be used willy-nilly and with different types at different places.
<Smerdyakov> stevan, you get better engineering properties defining it in one place.
<stevan> my database module defines a simple variant for basic SQL-ish types, and they are pretty much the same as my JSON module. You would suggest I define conversion functions ,.. even if they are pretty much trivial?
<haelix> Smerdyakov I'll think of that, and will have other questions :)
<stevan> Smerdyakov: btw - how was POPL?
<Smerdyakov> stevan, no, you should define the types in another module that both use,.
<Smerdyakov> stevan, POPL was OK.
<stevan> Smerdyakov: only OK?
<Smerdyakov> stevan, that's right.
vorago has joined #ocaml
<vorago> Hi.
oscarh has joined #ocaml
Naked has joined #ocaml
Naked is now known as Hadaka
bluestorm has joined #ocaml
<pango> polymorphic variants constructors are represented by a hash value, not a string
romanoffi has left #ocaml []
_JusSx_ has joined #ocaml
<fincher> pango: but the string still has to be kept around, since they can't guarantee a perfect hash in the face of modular compilation.
<pango> I don't know if collision is tested at link time, or at runtime when the program starts
<pango> either way, I think the result is that the program stops
<pango> that's a program to find collisions in a set of strings, with different hashing algorithms...
<flux-> hmm.. if the collisions were handled during program startup, wouldn't it be possible to just assign numbers to them and avoid hashing altogether..
<flux-> but then interfacing with C would be different, and that (interfacing with C) has been one rationale I've heard for the existence of polymoprhic variants
<pango> I guess dynamic loading of bytecode is still an issue... I haven't tested what happens in case of collision
pinupgeek has joined #ocaml
<flux-> the renumbering would need to be reperformed on such events
pango_ has joined #ocaml
<hcarty> Is there a way to match against "any of this variant type"?
pango has quit [Remote closed the connection]
<flux-> hm?
<love-pingoo> #type
<love-pingoo> | (#positive as p)::gamma ->
<flux-> that works only with polymorphic variants, right?
<love-pingoo> yes
<love-pingoo> _ is enough for core variants
sponge45 has joined #ocaml
slowriot has joined #ocaml
buluca has quit ["Leaving."]
zmdkrbou_ has joined #ocaml
pinupgeek has quit ["Goodbye Ruby in the dust"]
zmdkrbou has quit [Read error: 110 (Connection timed out)]
Z4rd0Z has quit []
david_koontz has joined #ocaml
romanoffi has joined #ocaml
smimou has joined #ocaml
Anusien has joined #ocaml
Aradorn has left #ocaml []
<hcarty> Can you recommend any good docs, beyond chapter 2 of the OCaml manual, on functors?
<hcarty> I'm trying to wrap my brain around them and implement something. Some extra examples would help and Google isn't providing much help.
<ulfdoz> hcarty:
<ulfdoz> mompl.
<ulfdoz> hcarty: Mac Lane, "Categories for the working Mathematician"
<Anusien> when you're doing matching, for example: | head::tail -> ...
<Anusien> How do you signify multiple statements there
<ulfdoz> iirc correctly, a functor is nothing more, than an injection from one category to another.
<bluestorm> Anusien:
<bluestorm> | ... -> (... ; ... )
<Anusien> would this work?: http://rafb.net/p/VDmTxF28.html
<bluestorm> instead of ( ... ; ... ) you can use begin ... ; ... end
<bluestorm> Anusien: yes
<Anusien> assuming I fix the syntax errors
<Anusien> sweet, I may grok ML yet
<bluestorm> but foo has to be of type unit
<Anusien> why?
<bluestorm> orelse you should provide an "else" alternative
<Anusien> alright
<hcarty> ulfdoz: Thanks - I'm trying to see if they'll save me some code/copying and pasting
<bluestorm> (without else you may think the compiler add a "else ()" clause)
<bluestorm> Anusien:
<bluestorm> after a -> you can put an expression
<ulfdoz> hcarty: For lists, map is often a functor.
<bluestorm> "let a = expr in expr" is an expression
<bluestorm> "if bool then expr else expr" is an expression
<bluestorm> and "expr; expr" is an expression too
zmdkrbou_ is now known as zmdkrbou
<ulfdoz> hcarty: You can think about it as a transformer. For example, creating a binary tree from a list.
<bluestorm> hmmm Anusien
<Anusien> The goal is to look in an array and see how many times the item is there. For each one, check and see if it's in depCount, and if it's not, add it. depCount is (int, string) tuples
<bluestorm> let -> let rec
<bluestorm> hmm
<ulfdoz> map was the wrong example. fold* is better.
<Anusien> now I need to figure out how to make that function loop recurse through tasks
<bluestorm> for now your function doesn't have any argument
<Anusien> can I say "head :: tail + foo" and concenate parts of lsits that way?
<bluestorm> hum
<bluestorm> what's foo ?
<ulfdoz> Mag ja sein, dass Bücher eine kulturelle Lücke bei mir sind, aber der Deutschunterricht hat es versaut.
<Anusien> I need to take that let statement and make it a recursive function such that it checks that way over each element in the list
<ulfdoz> ECHAN, sorry
<bluestorm> Anusien: first give him an argument
<bluestorm> for now it isn't a function
<bluestorm> hum
<Anusien> I know, I need to make it one
<Anusien> what do you mean give him an argument?
<bluestorm> hum
<bluestorm> a parameter
<Anusien> isn't "tasks" a parameter? Tasks is a list
<bluestorm> let depCount = match tasks with
<bluestorm> tasks isn't a parameter of depCount
<bluestorm> let depcount tasks = match tasks with
<bluestorm> would be ok
<Anusien> I don't know what you mean with that last example
<bluestorm> it's the same as let depcount = fun tasks -> match tasks with
<Anusien> ideally depCount is a list
<Anusien> of duples
<bluestorm> hmm
<Anusien> Is there some ML example code I can look at, for sorting (for instance)?
<bluestorm> (are you using Ocaml or another ML language ?
<bluestorm> )
<Anusien> ocamlo
<Anusien> err, ocaml
<bluestorm> hum
<Anusien> http://rafb.net/p/411vnk36.html <-- I found this. in line 2, what does "fp l" mean?
<bluestorm> did you know http://ocaml-tutorial.org/ ?
<bluestorm> "let rec fp l = ..." is a declaration
<Anusien> hrm, no. Thanks, I'll fiddle with this
<bluestorm> hum
<bluestorm> i have to go for now
<bluestorm> have fun :p
<Anusien> Alright, thanks
slowriot has quit [Connection timed out]
trurl has quit ["Changing server"]
trurl has joined #ocaml
postalchris has joined #ocaml
<pango_> Anusien: in your example, tasks looks like a list, not an array
<Anusien> It's possible. I've done quite a bit of modifying it since then, and I'm sure it's mostly incorrect
<Anusien> Wait, what's the difference between a list and an array?
<pango_> there's plenty
<Anusien> [] signifies a list or an array?
<pango_> list
<Anusien> and foo :: bar joins lists?
<pango_> it returns a list made by consing an element at the head of a list
<pango_> if foo is of type 'a and bar of type 'a list, foo :: bar is of type 'a list
<Anusien> type 'a is?
<pango_> 'a is a type variable... it can be anything
<Anusien> Is there a site that gives better function explanations? I'm trying to find out how to use List.sort
<pango_> it takes a function to compare two elements, a list, and returns the sorted list
chi11 has quit ["I'm outta here ..."]
<pango_> the function should have the same contract as Pervasives.compare: return a negative result if the first element is "smaller" than the second, positive if it's "larger", and zero if they're "equal"
<Anusien> ah, that's what it meant when it said int
buluca has joined #ocaml
<pango_> man List
<pango_> or look at list.mli in ocaml's libraries directory
<Anusien> where is the ocaml library directory?
<pango_> $ ocamlc -where
<Anusien> alright, thanks
<Anusien> do I need anything to signify that my if/else block is done?
<Anusien> In writing .ml, not running it from the toploop
<Anusien> ALl the guides I've seen are almost strictly from the top loop
<pango_> there's no such thing as if/else block
<Anusien> err
<Anusien> oh I see
<Anusien> begin .. end
<Anusien> is let <foo> <args...> = begin ..;..;.. end valid?
<pango_> that should work... you can also use parens instead of begin and end
<Anusien> you mean ()s? or {}s?
<pango_> ( )
<Anusien> Alright, thanks. Once more into the fray
<cjeris> you will get a warning if the thing before the ; is not of type unit; you can shut this warning up by making use of ignore: 'a -> unit
<cjeris> let f x = begin (ignore 1); 2 end;;
<pango_> if you get a warning, that's because it's usually a bug
<cjeris> well, yes. you say ignore when you mean ignore :)
<pango_> doesn't feel like a good tip for a beginner
<cjeris> i suppose that's fair.
<pango_> Anusien: let ... and let ... in ... introduce open ended blocks, that's why you seldom see begin end used that way
_JusSx_ has quit [Client Quit]
<Anusien> okay, I feel like I'm missing something simple, but I can't find it in any of the docs. How do I get all but the last item in a list?
<pango_> with difficulty
<Anusien> have to do it recursively?
<pango_> lists aren't symetric, taking their head of tail to the left is O(1)
<pango_> but not from the right
<Anusien> right, I get that
<Anusien> something like: http://rafb.net/p/Gn0Qvl83.html
<pango_> s/of/or/
<pango_> Anusien: did you try compiling this code ?
<Anusien> no
<pango_> last case is never used, and the compiler will tell you so
<Anusien> I'm dreading compiling it, it's about 60 lines
<Anusien> is there a way to check if it is just one element then, and then put that check above head :: tail?
<Anusien> something like head :: null?
<pango_> head :: [], or just [head]
<Anusien> ah, thanks
<pango_> still, your recursive call is incorrect
<Anusien> how so?
<pango_> head :: popLast (tail) will rebuild the original list
<Anusien> http://rafb.net/p/jkgA9p49.html <-- that will?
<pango_> oh mmh sorry, yes, the list without the last element... yes, that's correct
<pango_> the () around tail aren't needed however
<Anusien> alright. Thanks so much
<Anusien> http://rafb.net/p/tCThDs97.html <-- wil return only the last element, right?
tsuyoshi has quit ["brb, restarting irssi"]
<pango_> Anusien: thinking of your previous function, there's a problem of types however
<Anusien> how so?
<pango_> all cases must evaluate to values of the same type
<pango_> since the first case returns a 'a list, head must also be a 'a list in the second case
<Anusien> I see
<pango_> so x must be a 'a list list
<Anusien> I'm not sure I understand what you mean
<pango_> ocaml is a strongly statically typed language, all expressions have a type determined at compile time
<Anusien> right
<pango_> all the branches of a match must have the same type, since it's also the type of the match expression as a whole
<Anusien> I understnad that. Specifically though I don't think I know what you're referring to
tsuyoshi has joined #ocaml
<pango_> since the first case returns [], all branches must return lists ('a list, for some type 'a)
<Anusien> so that second line [head] -> head is a problem, right?
<pango_> hence head is of type 'a list too, for the same 'a
<pango_> and [head] is a list of 'a lists, so is a 'a list list
<pango_> ocaml will infer that the parameter of your function must be a list of lists, which is probably not what you wanted
<Anusien> ahh
<pango_> you could solve that by raising an exception if the function receives an empty list... After all, there's no good result in that case
<pango_> [] -> failwith "popLast of empty list" (or whatever)
slowriot has joined #ocaml
<pango_> # failwith ;;
<pango_> - : string -> 'a = <fun>
<pango_> failwith doesn't return, and it has been given (arbitrarily ?) a polymorphic signature, so it won't add extra type constraints with your other match branches
<Anusien> hrm
<Anusien> there is a way to create an array from a list, right?
<Anusien> oh, wait, here it is
<pango_> # Array.of_list ;;
<pango_> - : 'a list -> 'a array = <fun>
slowriot has quit []
Z4rd0Z has joined #ocaml
<Anusien> do .. done is a set, right?
<bluestorm> hum, actually, i think "for .. = .. to .. do ... done" is one, and "while .. do ... done" is another
<Anusien> yes, but what I meant was that done closes a do block
<pango_> yes, but they only exist of the context of a for, or a while construct
cjeris has left #ocaml []
<Anusien> now, ehre comes debugging this behemoth of a program
<Anusien> In some example programs I see varying use of semicolons, where is that explained?
<pango_> they're used for sequences, lists, arrays... is that what you mean ?
<Anusien> This is the example program in the .pdf guide: http://rafb.net/p/7ncp8y52.html
<pango_> I only see ; and ;; there
<Anusien> right. It never explains when each get used though
<pango_> See "Using and omitting ;; and ;" in http://www.ocaml-tutorial.org/the_structure_of_ocaml_programs
<Anusien> thank you
bluestorm has quit ["Konversation terminated!"]
Z4rd0Z has quit []