<adrien>
I don't think having bindings for ocaml would make it more usable to me (I've only dabbled with the C++ API)
<mrm>
Hello. Can anyone tell me if the latest version of Batteries (the 2.0, which does not depend on Camomile) is useable for production?
<mrm>
I want to get rid of Camomile, because it's a pain on Windows :-(
<wmeyer>
mrm: but you don't want unicode or you want?
<wmeyer>
I mean trunk worked fine; and i was suprised that it didn't have unicode modules anyway; i was that lucky person who wanted to use unicode and upgraded batteries to trunk
<wmeyer>
mrm: that was some while ago, and the project was relatively small
<mrm>
wmeyer: I don't really need any functionality of Camomile. On Windows it's problematic to distribute binaries dependent on Camomile because it requires some database located on the filesystem
<mrm>
xavierm02: The ones when you have to send a program to an online judge system?
<mrm>
xavierm02: e.g. codeforces.com, spoj.pl and alike
<xavierm02>
yeah
<mrm>
I did it with OCaml and had no problem with IO whatsoever
<xavierm02>
well
<xavierm02>
the site i need to send it to
<xavierm02>
won't give me a filename
<xavierm02>
so
<xavierm02>
it should "work" with what i wrote
<mrm>
It gives you input through stdin, right?
<xavierm02>
yes
<xavierm02>
so it should work
<xavierm02>
but i dont know
<xavierm02>
how to myself give it input though stdin
<mrm>
It should.
<xavierm02>
i thought
<xavierm02>
cat file.txt | ocaml thing.ml
<xavierm02>
would work
<xavierm02>
but it doesnt
<xavierm02>
i can do
vpm has joined #ocaml
<xavierm02>
ocaml thing.ml
<xavierm02>
and then write all the input
<mrm>
xavierm02: Perhaps you forgot the last newline in a file?
<xavierm02>
but since i'll have to test amny times
<xavierm02>
this is kind of long
<xavierm02>
i just added 10 linmes at end of file
<xavierm02>
still doesnt work :/
<xavierm02>
i think
<xavierm02>
it just doesnt get the file at all
<mrm>
xavierm02: Send a program somewhere, please. To slexy.com, for example
<mrm>
xavierm02: I'll have a look
pango has quit [Ping timeout: 248 seconds]
<xavierm02>
it must have something to do with the Array.init n
<xavierm02>
because if i only leave
<xavierm02>
let n = Scanf.scanf "%d " ( fun x -> x ) in print_int (n)
<xavierm02>
in the thing.ml file
<xavierm02>
it works
<mrm>
Perhaps there is not enough input in your file. Try debugging the problem with print statements (not forgetting to flush IO)
<mrm>
xavierm02: I have stumbled upon similar problems when using OCaml in codejam. Once you learn of the corner cases, IO becomes as trivial as trivial it is when using other popular contest-programming languages
<xavierm02>
i think
<xavierm02>
it might be scanf
<xavierm02>
that goes through the whole file
<xavierm02>
for some reason
<mrm>
xavierm02: Don't think so. Most probably there is a bug in your program or there is not enough data in the input file
<xavierm02>
(And I'm just starting so I wanted to get things to work before making them look better ^.^)
<xavierm02>
I have another question
<mrm>
xavierm02: Is it possible to use third party libraries in the competition you participate in? I'd strongly suggest you to use Batteries -- an alternative standard library. OCaml's standard library is just waaay too tiny and limiting for the needs of programming contests. It'd force you to reinvent the wheel over and over again, in each competition :-(
<xavierm02>
welll
<xavierm02>
i dont think i does
<xavierm02>
but it doesnt have extraordinary needs
<xavierm02>
mainly simple stuff
<xavierm02>
at least at this stage
<xavierm02>
so
<xavierm02>
i have my string "o o"
<xavierm02>
how can I transform that into a list
<xavierm02>
of 1 and 0
<mrm>
xavierm02: Limited standard library is the main reason why I sometimes prefer Haskell instead of OCaml for programming contests :-(
<xavierm02>
it'll have to do some useless conversion
<xavierm02>
no?
<xavierm02>
here is the thing i need to solve
<xavierm02>
i get a bunch of lines
<xavierm02>
with spaces and o
<xavierm02>
and i must make sure
<xavierm02>
that if i take two lines
<xavierm02>
they only have one o in common
<xavierm02>
so i was thinking
<xavierm02>
i transform them into lists
<mrm>
xavierm02: in common = in one column?
<xavierm02>
yeah
<xavierm02>
but
<xavierm02>
only for 2
<xavierm02>
o o
<xavierm02>
oo
<xavierm02>
oo
<xavierm02>
for example
<xavierm02>
if you take two
<xavierm02>
you always have exactly one whole in common
<xavierm02>
i woudl tranform that into
<mrm>
xavierm02: Sure, why not. Transform both into lists, then make List.combine (to get a list of pairs), then List.filter (to find adjacent zeros), then List.count
<xavierm02>
[1, 0, 1]
<mrm>
and check if it's 1
<xavierm02>
yeah
<xavierm02>
but how do i tranform into lists?
<xavierm02>
i have to do a loop etc.?
<mrm>
String.to_list
<xavierm02>
i wouldve thought there would be a function for that
<xavierm02>
meh
<mrm>
xavierm02: Oh, wait. It's a function from Batteries!
<mrm>
xavierm02: There is no such function in the std
<xavierm02>
>_<
<mrm>
And that is an example of why Std sucks so much
<adrien>
Std?
<mrm>
It misses lots of useful functions
<mrm>
Standard library
<adrien>
ah, ok
<adrien>
it doesn't suck; it's limited on purpose
<mrm>
adrien: Yeah :-(
<mrm>
xavierm02: Got to go. Cya!
<xavierm02>
cya
<adrien>
I really wish there was a function to run a command and read its output
<adrien>
should be available out of the box
ankit9 has quit [Quit: Leaving]
mrm has quit [Ping timeout: 252 seconds]
tani has joined #ocaml
tane has quit [Ping timeout: 246 seconds]
rickmeizter has joined #ocaml
<rickmeizter>
hey guys
<rickmeizter>
i'm doing some homework but i've been stuck for hours on something i'm sure it's really stupid
<rickmeizter>
and I can't wrap my head around it
<rickmeizter>
can anybody give me a hand?
<rickmeizter>
basically, the exercise asks to define the function exp x n with the exponentiation by squaring algorithm
<rickmeizter>
to obtain x^n
<rickmeizter>
i've looked at the solution
<rickmeizter>
but i don't see how it can be working
<rickmeizter>
and so i would need someone to help me understand how the code works, mixing pattern matching with parameter omission in the fun statement
<rickmeizter>
please excuse me for using ^ as the math operator
<mrm>
rickmeizter: Are you sure that OCaml won't calculate n mod 2 twice?
<rickmeizter>
what do you mean?
<wmeyer>
is it possible at all to install pandoc? that needs first order logic inference engine to know.
<rickmeizter>
I don't know if that code I just posted works, it's just to represent my idea of how I'd do it
<mrm>
rickmeizter: I talk about efficiency. I'm not sure that such kind of a pattern-match sequence is going to be optimized
<mrm>
Just being picky :-)
<rickmeizter>
oh okay :)
<rickmeizter>
well i just started yesterday
<rickmeizter>
I just need to get the hang of it
<rickmeizter>
and then I will surely have an eye for that as well
* wmeyer
joins haskell to ask how to install package or what to do next
<adrien>
uninstall haskell :P
<wmeyer>
adrien: I need pandoc.
<adrien>
wmeyer: heheh, you have to love dependencies in package managers :-)
<wmeyer>
adrien: cabal seems to take this dependencies to extreme :-)
<wmeyer>
i am not sure if it's not a bug in cabal
<wmeyer>
or...
<adrien>
I believe repositories should never get into such states: public repos should always be consistent and never ever make it possible for users to have conflicting versions
<adrien>
if a conflict can arise, it's not ready
<adrien>
(and if you use backports, you're shooting yourself in more than the foot)
<wmeyer>
adrien: but that's a pristine version of haskell straight frome debian, i have done cabal upgrade too.
<wmeyer>
maybe there is .cabal directory in ~ i am sure there is ~~~
<adrien>
I hate most package managers which I consider over-engineered, trying to do too much, and answering the wrong questions
<adrien>
well, good luck, crêpes-time \o/
<wmeyer>
adrien: thanks for mental support
* wmeyer
calling an ambulance anyway
<wmeyer>
with my biggest hope: removing .cabal didn't help!
Developper has joined #ocaml
* wmeyer
being ignored on haskell. Cabal question? OCaml? or ... ?
ontologiae has quit [Ping timeout: 260 seconds]
<mrm>
wmeyer: Why not install Pandoc from the Debian repos?
<mrm>
I did so and it works beautifully
rickmeizter has quit [Ping timeout: 255 seconds]
<wmeyer>
mrm: I need the newest version
<wmeyer>
but i am ok with haskell distro from their website
Cyanure has quit [Remote host closed the connection]
<ng__>
how i use while loop in ocaml??? for example : let i=1; while (i <c) do printf("*"); i = i + 1 done;;
<ng__>
Is it correct?
* Kakadu
never used while loops
<Kakadu>
but
<Kakadu>
try this
<Kakadu>
let i = ref 1 in while !i < c do incr i; done;
<ng__>
ok
<ng__>
let me see
<ng__>
;D
Dettorer has quit [Quit: WeeChat 0.3.8]
Developper has quit [Ping timeout: 248 seconds]
jbrown__ is now known as |jbrown|
<ng__>
omg, i love this channel ;D
<|jbrown|>
ng__: while loops are pretty unusual in ocaml code IMO :-)
<ng__>
thanks Kakadu
<ng__>
yes, but i need practise ;D
<|jbrown|>
you know you can use "for i = 1 to c [...]" right? :-)
<ng__>
so in this moment i use every loops
<ng__>
:D
<ng__>
yes
<|jbrown|>
ok
* |jbrown|
stops interfering :-)
<ng__>
;D
<ng__>
thanks |jbrown|
Developper has joined #ocaml
Snark has quit [Quit: Quitte]
sgnb has quit [Read error: Connection reset by peer]
sgnb has joined #ocaml
ImAlsoGreg has quit [Quit: Leaving]
Neros has quit [Read error: Connection reset by peer]
Neros has joined #ocaml
<mrm>
wmeyer: I actually had to fix an extremely tricky bug in the latest Batteries before my project's testsuite ran succesfully :-) And it was one of the smaller projects (4k lines)
<mrm>
At least I'm going to contribute something back this way :-)
RichN has quit [Ping timeout: 256 seconds]
<wmeyer>
mrm: nice!
<mrm>
wmeyer: Did you know that "(==) == (==) -> false"?
<mrm>
Or that "compare == compare" evaluates to false?
<tac>
mrm: were you expecting any meaningful answer for testing if two functions were the same?
RichN has joined #ocaml
<tac>
At best, you can do pointer-equality on functions
<mrm>
It turns out that different occurences of external primitives are actually different closures during runtime
<tac>
at worst, the problem is undecidable
<mrm>
tac: Well, these are externals!
<tac>
ah, does ocaml actually *do* pointer equality on functions?
<wmeyer>
mrm: we should not rely on a functiona equality as tac says
<tac>
(I actually find that kinda surprising :)
<mrm>
tac: Yes, there is a physical comparison operator (==)
<mrm>
wmeyer: Well, (==) is used in Batteries here and there. We have to carefully check each use of the physical comparison operator. It's somewhat tricky
<wmeyer>
mrm: I'm not entirelly convinced by the changes you propose to the Batteries
<wmeyer>
it looks to me you rely that p_compare will not be inlined, of course now mayb it works
Developper has quit [Ping timeout: 256 seconds]
<mrm>
wmeyer: Well, some functions didn't work either way
<wmeyer>
and it's very fragile to compare functions anyway, if there is a functional value then you want just implement your own OrderedType
<mrm>
wmeyer: For example, polymorphic Map.unite was broken
<mrm>
wmeyer: If one needs better static guarantees, one is free to use a functorized interface to Maps
<wmeyer>
mrm: it would be better to mention in PMap doc if ever it happens that the user wants to do this, then it's required to use Map with the appropriate module passed
<mrm>
wmeyer: The whole point of polymorphic maps is not being required to define a module
<wmeyer>
mrm: I agree, but it's a bad practice. There is no compeling reason to not use functorised interface apart from the performance :-)
<mrm>
I often find PMaps to be adequate for my uses
<wmeyer>
yes, but then if you do define your data type including functionals they are already special
<wmeyer>
for instance marshalling is already special, comparision is already special
<mrm>
wmeyer: Less typing, less code :-) I want to be able to build prototypes faster. That's why I love polymorphic structures and variants :-)
<wmeyer>
mrm: I agree but then you can pass compare functions to be on a safe side
<wmeyer>
i really don't like the idea of comparing functional values :-)
<wmeyer>
it should not possible at the type level/compilation level
<wmeyer>
but then == should not be polymorphic
<wmeyer>
and then we hit the problem of requiring some sort of overloading
<mrm>
Me neither. I also don't understand in which case one could probably need a map unification/merge procedure that'd work on maps with different comparison functions :-)
<wmeyer>
Standard ML has a hack. Haskell has deriving and type classes.
Developper has joined #ocaml
<mrm>
I only need a simple PMap with a wired in Pervasives.compare function
<mrm>
If I'd ever need to specify a comparison function (I sometimes need), then I'd use the functorized interface
<xavierm02>
i have a question
<xavierm02>
I have a set of things
<xavierm02>
and I need to compare them to one another
<xavierm02>
with a symetric binary relation
uselpa has joined #ocaml
<xavierm02>
so what I
<xavierm02>
do
<xavierm02>
is i have two loops
<xavierm02>
and check for every combinaison
<xavierm02>
but
<xavierm02>
I think it would be way better to check it recursively
<xavierm02>
set_with_n_elements = set_with_n-1_elements + element
<xavierm02>
and i could have a function that would check a set
<xavierm02>
one that would check an element against a set
<xavierm02>
and one that would check two elements
<xavierm02>
and I know how to do that
<xavierm02>
but I am using lists
<xavierm02>
and I have no idea how to detect if they are emptyu
<xavierm02>
in another language
<xavierm02>
it would be
<xavierm02>
list.head == null
<xavierm02>
or something
<xavierm02>
but apparently
<xavierm02>
if you ask for the head of an empty list
<xavierm02>
you get an exception >_<
<xavierm02>
ah
<wmeyer>
xavierm02: if lst = [] then ... else ...
<wmeyer>
or better
<xavierm02>
i just though
<xavierm02>
i could use length
<xavierm02>
but that woudl suck
<xavierm02>
cuz geting length
<xavierm02>
is O(n)
<wmeyer>
match lst with [] -> ... | case1 -> ... | case2 -> ...
<xavierm02>
ty :)
<xavierm02>
is there a way
<xavierm02>
to do
<xavierm02>
math lst with [ head, rest... ] ->...
<wmeyer>
mrm: actually your patch maybe makes sense in the setting where PMap should do it best to compare reliably, but a hack for documentation would be probably required to let the users of PMap know.
<xavierm02>
or something?
<wmeyer>
of course
<wmeyer>
match lst with head :: rest -> ...
<xavierm02>
with that syntax?
<xavierm02>
ok
<xavierm02>
ty
<wmeyer>
match lst with [first_element; second_element] -> ...
<wmeyer>
assuming in the second case your list has just two elements.
<wmeyer>
if you want to match first two elements and rest
<wmeyer>
then
<wmeyer>
match lst with first_element :: second_element :: rest -> ...
<wmeyer>
which is the same as
<wmeyer>
match lst with first_element :: (second_element :: rest) -> ...
<mrm>
wmeyer: Sure. It needs to be made very clear to the users that polymorphic containers are dangerous tools which should be used with caution. When I was new to OCaml, I thought that PMaps and PSets from Extlib are the way to go (and surely got my ass burned on several occasions, before learning of all the gritty corner cases).
<wmeyer>
but adding a sentence or two saying that definitely it's unsafe to use if for the functional values would be great.
tac has quit [Ping timeout: 245 seconds]
Tobu has quit [Quit: No Ping reply in 180 seconds.]
Tobu has joined #ocaml
cdidd has quit [Read error: Connection reset by peer]
<xavierm02>
is head :: tail the only way of matching a list of arbitrary length?
<xavierm02>
or is there another way of doing it
<xavierm02>
if you don;t actually need those two elements?
<xavierm02>
_ :: _ ?
andreypopp has joined #ocaml
<adrien>
yes, yes
<adrien>
you can also _head :: _tail
<adrien>
it names the values but indicates you're not going to use them
<adrien>
it's handy to show intent
<mrm>
wmeyer: The fix which I hacked up has nothing to do with users putting functional values into maps (that'd be quite dangerous with both Maps and PMaps). It is an entirely internal problem which arises when using certain functions (union, diff, intersect) on polymorphic maps. I just propose a hacky workaround to make it work somehow. A proper solution would involve decoupling the code of polymorphic maps from the code of functorized maps
<mrm>
to get rid of all the "comparison function comparisons" :-). Perhaps I will do it.
tac-tics has joined #ocaml
<xavierm02>
ok
<xavierm02>
yet another question
<xavierm02>
how can I differentiat
<xavierm02>
a list containing lists
<xavierm02>
from a list containing interger?
Developper has quit [Quit: leaving]
<adrien>
the type system will do it
<adrien>
what do you want to do that for?
<xavierm02>
well
<xavierm02>
i have items
<xavierm02>
pins
<xavierm02>
and i want to do a function
<xavierm02>
no
<xavierm02>
i have a binary relation
<xavierm02>
between pins
<xavierm02>
R( pin1, pin2 ) = true or false
<xavierm02>
and
<xavierm02>
i want a function
<xavierm02>
that would take sets of pins
Neros has quit [Ping timeout: 264 seconds]
<xavierm02>
or a pin and a set
<xavierm02>
or two pins
<xavierm02>
and return whether
<xavierm02>
for each combinaison of elements
<xavierm02>
R( pin1, pin2 ) is true
<xavierm02>
I could do it with 3 functions
<xavierm02>
but I find is cooler to do it with one ^.^
<xavierm02>
plus I'm doing it to learn anyway
<xavierm02>
example
<xavierm02>
R(a, b) = true = R(b,a)
<xavierm02>
R(a,a) = false = R(b,b)
<xavierm02>
so
<xavierm02>
f( a, b ) = true
<xavierm02>
f( {a, b }, a ) = false because R(a, a ) = false
<xavierm02>
f( { a, b }, {a} ) = false for the same reason
<xavierm02>
and I represent sets with lists
Neros has joined #ocaml
Tobu has quit [Ping timeout: 260 seconds]
uselpa has quit [Remote host closed the connection]
<ng__>
( n != exponentiation(2)) how i write this in ocaml??
<|jbrown|>
the mathematical exponent? Like e^n? "n <> exp 2.0"
Neros has quit [Remote host closed the connection]
Tobu has joined #ocaml
<ng__>
|jbrown|, exactly, but a friend mine, said to me something i can use for the exponent with "**"....
<|jbrown|>
** is "pow" in C
<|jbrown|>
whereas exp is exp
<ng__>
ah ok ;D
<ng__>
thanks
cdidd has joined #ocaml
Anarchos has joined #ocaml
<mrm>
ng__: By the way, one should be very careful when using equality comparisons with floats. That is almost always a wrong way to go
<ng__>
mrm, Oo
<ng__>
This expression has type float but an expression was expected of typ
<ng__>
I´m trying to solve this ...
<mrm>
ng__: Paste the expression you are trying to evaluate
avsm has joined #ocaml
<mrm>
xavierm02: Extremely confusing explanation of a problem :-)
andreypopp has quit [Quit: sleep]
<ng__>
mrm, for example this : " if ( n != 15.5 ** 2.0 ) then "
<mrm>
ng__: It works for me. Provide the complete error message.
<mrm>
"This expression has type float but an expression was expected of typ" ... -> what next?
<adrien>
!= is the wrong operator
<adrien>
you would want <>
<adrien>
but as previously stated, don't compare floats for equality
<adrien>
floats are not exact values
<mrm>
Yeah, but he shouldn't get a type error, unless n is not a float
<adrien>
adding one and then substracting one to a value might give a different value
jave has quit [Ping timeout: 260 seconds]
<adrien>
agreed but good luck getting any (==) equality over floats
<ng__>
"This expression has type int but an expression was expected of type float"
<adrien>
then 'n' is an int
mnabil has joined #ocaml
<mrm>
ng__: != operator requires that its operands to be of the same type
<mrm>
ng__: same with other standard infix functions
<mrm>
n is an integer because read_int has a signature of [unit -> int = <fun>]
<Anarchos>
mrm as read_int gives the hint ;)
<mrm>
ng__: the result of ** is a float because the signature of ** is [float -> float -> float = <fun>]
<mrm>
ng__: and == is ['a -> 'a -> bool = <fun>]. That is, it expects its arguments to be of the same type
<ng__>
yes, but I put as int and equal appears
<ng__>
the same message
<mrm>
ng__: Because the compiler doesn't understand how to match an int, a float and an equality operator which expects its arguments to be of the same type
<mrm>
ng__: I suggest you to read some introductory text on the ML type systems
<wmeyer>
ng__: Hold on, you have two things to remember: == is equal to comparing by reference in Java or pointers in C++. From standard primitives types nly ints can be compared equaly good with == because they are values not references. Floats are boxed - they are locations on heap, so the == will compare the pointers. = however will compare always the values by traversing into the structures and following it's values. So use always
<wmeyer>
exceptions when you want to know if the OCaml values refer to the same location. != is reverse ==, and <> is reverse =. So for floats you need = and <>, plus adrien 's remark that in case of floats standard rules obey - don't check for equality by bits but by epsilon intervals.
<mrm>
*I suggest that
<mrm>
(tricky verb)
answer_42 has quit [Ping timeout: 276 seconds]
<wmeyer>
ng__: apart from that I suggest like ng__ have suggested, reading some good explanatory book about the type system, it might help you understand basic concepts
<mrm>
Standard exceptions are checking for NaN's and for zeros (in some very rare cases) :-)
<wmeyer>
mrm: I think floats are equaly controversial as polymorphic equality operators :-)
avsm has quit [Quit: Leaving.]
jave has joined #ocaml
<mrm>
wmeyer: Yeah. I currently have to deal with code ripe with direct float comparisons (there are some "special" constants like -999.25). It's full of ridiculous float-specific bugs :-(
<ng__>
ah ok, thanks... i understand what you said to me :D... sorry for writing too little, but my English is not the best ;D
<wmeyer>
ng__: no problem, enjoy :-)
<ng__>
:D
jave has quit [Read error: Operation timed out]
<mrm>
wmeyer: I had to fix another bug to make my second project pass the tests with the latest Batteries
<mrm>
Perhaps there are some more subtle bugs which haven't been detected by my testsuites :-( I think it's currently way too early to switch to the newest Batteries for production work. It took a long time for the 1.x branch to become truly stable.
<wmeyer>
mrm: it's best then to send a pull request to approriate people with these bugfixes. Ping thelema, he will be very happy to see these bug fixes.
<mrm>
wmeyer: Oh. I somehow thought you were one of the Batteries guys
<wmeyer>
mrm: if it's possible I would personaly have a shot with 2, and try to port your bigger programs, and then report back problems.
<wmeyer>
mrm: No, I'm not :-)
ontologiae has joined #ocaml
<mrm>
wmeyer: By the way, aren't you Wojciech Meyer, the author of DragonKit?