<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
<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
<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 ?
<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_>
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