polin8 has quit ["Now _that's_ a good cup of coffee."]
polin8 has joined #ocaml
seth has joined #ocaml
<seth>
anybody home?
<Riastradh>
<--
<docelic>
<-- free beer here.
<seth>
I'm somewhat new to ocaml and I could use some help figuring out what the manual is telling me in a few places.
<seth>
for example, I'm look at the docs for Module Arg. The first line says: module Arg: sig end is "sig end" a type?
<Riastradh>
It's a module type, yes.
<seth>
where is that type defined?
<seth>
or is it a build in type?
<Riastradh>
It isn't 'defined' -- 'sig <signature elements> end' is how you write signature types.
<Riastradh>
Much like 'foo * bar * baz' is how you write tuple types.
<seth>
oh, ok, I read about signatures but didn't associate it with this.
<seth>
OK, now for the argument to Arg.parse, it specified a list of (string * spec * string). The middle type (spec) has constructors, one of which is Int. How would I write the triplet for an Int argument? the first string is the argument key and the third is a doc string.
<Riastradh>
("foo", Int bar, "baz")
<seth>
and that defines a new value bar?
<Riastradh>
It doesn't define it; bar is just any value acceptable to pass to Int.
<seth>
I'm not clear then about how the access the value of the argument after I run Arg.parse
<seth>
I've done a lot of Haskell but I'm somewhat rusty on functional syntax.
<seth>
is bar a dummy?
<seth>
a related question, can I find more example programs anywhere? I looked on the site but I didn't see examples of core and standard libraries. There are some with the distribution, but are there others available?
<seth>
Ah, I found some examples using Arg in some of the provided utilities. :)
* Riastradh
personally prefers Haskell to OCaml.
<seth>
I don't know enough about OCaml yet to say. I do like Haskell a lot.
<seth>
why does this work: let load_path = ref [""] but this doesn't let port = ref [""]
<seth>
never mind, there is a syntax error on the following line.
TimFreeman has joined #ocaml
TimFreeman has left #ocaml []
docelic is now known as docelic|sleepo
<seth>
How do I display a value? Printf.printf? If so can you show me an example?
<whee>
there's some print_* functions in Pervasives for basic values, and the Printf module is of course there for more complex formatting
<whee>
you'd go and Printf.printf "some format string" bunch of arguments
<whee>
like Printf.printf "%d %d %f\n" 10 20 30.3
Kinners has left #ocaml []
lament has joined #ocaml
Jimzy has joined #ocaml
<seth>
whee: is layout significant in ocaml, as in Haskell?
<mrvn>
layout? indentaition style?
<mrvn>
no way. Write everything in one line and your still fine.
<seth>
mrvn: do statements need to end with a semicolon?
<mrvn>
semicolons are for sequenzes, lists, arrays and streams.
<seth>
is there an emacs mode for ocaml?
<mrvn>
two, look for tuareg
Riastrad1 has joined #ocaml
Riastradh has quit [Connection reset by peer]
<seth>
found it, thanks.
lowks has joined #ocaml
<lowks>
ummm i am having problems installing ocaml labltk
<lowks>
fails
<lowks>
what version of tk / tcl does it need ?
<lowks>
version-3.0.6
lament_ has joined #ocaml
lament has quit [Killed (NickServ (Ghost: lament_!~lament@h24-78-145-92.vc.shawcable.net))]
lament_ is now known as lament
<lowks>
?
mattam has joined #ocaml
TimFreeman has joined #ocaml
<mrvn>
apt-get install ocaml
<mrvn>
life can be so easy.
<lowks>
mrvn: i am writing a spell for sorcerr
lament is now known as mal-2
mal-2 has quit ["Support Darwin Awards! Join the military!"]
K_music is now known as Krystof
systems has joined #ocaml
<systems>
slut
<systems>
ooops
<systems>
salut
<systems>
:P
<pattern_>
!
docelic|sleepo is now known as docelic
docelic has quit ["brb"]
docelic has joined #ocaml
docelic has quit [Read error: 104 (Connection reset by peer)]
systems has quit [Read error: 110 (Connection timed out)]
docelic has joined #ocaml
thedark has joined #ocaml
<thedark>
he, i need some help on a function...
<thedark>
let test (a:big_int) (k:big_int) (n:big_int) =
<thedark>
1;;
<thedark>
when i try test 5 0 5 (or something else) it's not giving me again the #prompt.... it just hangs ...
thedark has left #ocaml []
<mrvn>
of cause, why should it?
<mrvn>
and it doesn't hang. It just waits for you to input
thedark has joined #ocaml
<thedark>
how do i print "hello world" in caml?
<mrvn>
print_string "Hello world\n";;
<pattern_>
print_endline "Hello world";;
<pattern_>
;)
gene9 has joined #ocaml
Riastrad1 is now known as Riastradh
<thedark>
ok pattern_, i'll try this
<pattern_>
go all out, thedark! ;)
<pattern_>
you write the best damn hello world program ever :)
<thedark>
well i'm writing a program to test if a big int is a prime number, and it's not that easy ....when you dont know the ocaml langage
<mrvn>
Do it with ints first.
<thedark>
well it's almost done with big_ints
<thedark>
i'm testing it now ...
<thedark>
i get the message Exception: Failure "equal: abstract value". : i know what it means, but how can i know where in my program the error did occured ?
<mrvn>
add some prints
<thedark>
no other way to do that?
<mrvn>
I sometimes hate that exceptions aren't part of a functions type.
<mrvn>
In C++ you can specify what exception a function can throw.
<thedark>
same in java
<mellum>
In practise, that leads to more problenms than it solves
<thedark>
isnt there something like a camel debugger so i can know where the error did occur?
<mrvn>
One wouldn't get exceptions thrown out of the blue.
<mrvn>
thedark: there is but i don#t think it helps.
<mrvn>
Haven't seen a debugger yet that gets it when there is an uncaught exception before the program terminates with it.
<thedark>
and how do i print something into a function ?
gene9 has quit []
<thedark>
... nobody can tell me how to print something in a function ?
<mellum>
print_string "something"
<thedark>
well i'm in trouble with this
<thedark>
if i do this :
<thedark>
let rabin_test (n:big_int)(k:big_int) =
<thedark>
print_string "something"
<thedark>
rabin_test2 n 4;;
<thedark>
it tells me : This function is applied to too many arguments
<pattern_>
print_string "something" ;
<mellum>
Well, it is. You need to mark the end of the arguments to print_string with a ';'
<thedark>
ok
<pattern_>
where semicolons go is the most confusing thing about ocaml syntax, imo
<thedark>
is the output buffered? i mean is it possible that i dont see something printed BEFORE an error cause of the buffer?
<mellum>
thedark: yes
<thedark>
how do i flush the buffer so?
<mellum>
although a program dying should flush all buffers
<mellum>
let somefunc ((Letter (letter, fin, subnodes)) as x) = x;;
<Vincenz>
ah alright :)
<mellum>
that what you meant?
<Vincenz>
yup :)
<Vincenz>
can you do partial eval on functions?
<Vincenz>
like...
<Vincenz>
somefunc x y
<Vincenz>
(somefunc 0)
TachYon has joined #ocaml
<mellum>
Vincenz: yes
<Vincenz>
thought so, wasn't sure as it's crashing again
<mellum>
Vincenz: it's a very powerful tool sometimes
<Vincenz>
yup :)
<Vincenz>
woo !
<Vincenz>
let's see if insert works
<thedark>
i need to write a function that generates a random big_int lower than another big_int (as let i= Random.int j in) but for the bigints ...
<thedark>
can someone help me on that.. i dont know how to do:(
<Vincenz>
thedark: easiest solution
<Vincenz>
let's say your high_val....
<Vincenz>
then...
<Vincenz>
generate enough ints that the max is bigger than high_val
<Vincenz>
add it and mod high_val
<Vincenz>
though statistically speaking it's not exactly correct
<Vincenz>
(more of a guassian curve, plus some nonlinearity through the modding)
<Vincenz>
better
<Vincenz>
:
<thedark>
i've thought on this way to generate it but i need a "better" way...it's for testing some prime numbers so i need a "real" random number, although it wont be really random with a computer
<Vincenz>
let's say your number's closest power of 2 bigger than a certain number
<Vincenz>
has x bits
<Vincenz>
divide x by 30
<Vincenz>
generate that many numbers of 30 bits
<Vincenz>
put them after each other
<Vincenz>
(by multiplying/shifting and then adding)
<Vincenz>
and then mod it the high_val
<Vincenz>
you remove the gaussian effect
<Vincenz>
but some values will still have a higher probability if high_val isn't an exact power of 2
<Vincenz>
(because of the wrapping effect of mod)
<thedark>
i guess i'll just put some 0s and 1s together and wait till it reach my high_val ...
<Vincenz>
that's what I said
<Vincenz>
except I do it 30 bit at a time
<thedark>
well... why do u need a mod ?
<Vincenz>
(30 bits of randomnumber1).(30 bits of randomnumber 2).....(remaing bits to get it to the smallest power of 2 > high_val)
<Vincenz>
because the number generated will be a random number between
<Vincenz>
0
<Vincenz>
and 2^n - 1
TachYon has quit [Remote closed the connection]
<Vincenz>
where 2^n is the smallest number bigger than highval
<thedark>
ok
<thedark>
i'll try to write such a fonction.....
<thedark>
how do i print a big_int on the screen ?
<thedark>
what a strange idea to write a prime number testing program in a langage that i dont know :(
<Vincenz>
hmm...when matching a list can you do something like the following
<Vincenz>
| Letter(a, b, c)::moreletters ->
<Vincenz>
or is that too complex?
<Vincenz>
thedark: best way to learn :)
<thedark>
Vincenz: thats why i'm doing it :)
<Vincenz>
heh, me too, learning Ocaml :)
polin8 has quit [Read error: 104 (Connection reset by peer)]
<Vincenz>
woo!!!
<Vincenz>
it works :)))
<Vincenz>
anyone care to review my code?
<Vincenz>
perhaps there's way better ways to do it
<Vincenz>
(cause in this chapter they taught about List.map, but I didn't have to use it...)
<thedark>
how do i make a remark in ocaml?
<Vincenz>
(* someremark *)
<Vincenz>
multiline and nestable IIRC
dskippy has joined #ocaml
<thedark>
ok
<Vincenz>
anyone care to take a look at my code and see how it could be done better?
<Vincenz>
(it's not a lot)
<thedark>
well it would have been a pleasure, but i'm sure u'r more advanced than i am :)
<Vincenz>
not really :P
<Vincenz>
hmm
<Vincenz>
let funcname some param = function
<Vincenz>
| bla..
<Vincenz>
do I need to add the function?
<Vincenz>
can't it be
<Vincenz>
let funcname some param
<Vincenz>
| bla
<thedark>
u can do :
<thedark>
let funcname some param =
<thedark>
| bla ;;
<thedark>
another question: i want to test my program with some big_ints.. but how can i give ocaml such a big_int ? (of course functionname (big_int_of_int foo);; wont test the program on something bigger than an int ...
<Vincenz>
never worked with big_ints sorry
<emu>
doesn't it suck to have shitty support for numbers
<emu>
should pester the ocaml maintainers about that
polin8 has joined #ocaml
<seth_>
I'm compiling a program using the Unix module and getting "Reference to undefined global Unix." Do I need to explicitly link to a library?
<mattam>
yes
<emu>
you need to eunuchs yourself
<emu>
get with the program--it's global
<seth_>
mattam: what's the syntax?
<emu>
5%
<Vincenz>
#load "Unix.cma" or something like that
<seth_>
OK. I was trying open
<mattam>
smthing like -custom -ccopt -lunix for native code
<seth_>
no, that doesn't work. I'm compiling, not using the interactive interpreter.
<seth_>
mattam: ok, I"ll try that.
<mattam>
using OCamlMakefile could ease the process though
<seth_>
mattam: is OCamlMakefile a separate package? I don't see it in the distribution.
<mattam>
yes, it's just one file you can include to get a bunch of targets like byte-code, profiling and debugging
<mattam>
I can send it to you if you want
<mattam>
it has also threads and libs support, even camlp4
<Vincenz>
how do I turn a char into a string?
<emu>
magic wand
<Vincenz>
..
* Vincenz
sighs
<Vincenz>
I'm sorta stuck on a problem
<mattam>
String.make 1 char ?
dskippy has quit [Read error: 60 (Operation timed out)]
<Vincenz>
oh
<Vincenz>
neat :)
<Vincenz>
Anyone care to gimme a hand with some code?
<mellum>
Not me, I need to go to bed :)
<Riastradh>
How long is it?
<Vincenz>
the function that isn't working about 8 lines
<Riastradh>
OK, paste it here...I may be able to help.