mbishop changed the topic of #ocaml to: Discussions about the OCaml programming language | http://caml.inria.fr/ | Grab Ocaml 3.10.0 from http://caml.inria.fr/ocaml/release.html (featuring new camlp4 and more!)
<laynor> noob question: let's say I want to have a list that contains ints or floats, are variant types the best/only way to go? what about a "sum x y" function wich takes int or float arguments?
<pango_> there's no such thing as a "list of ints or floats" in OCaml types
<laynor> pango_: I know, I'm asking if the best way to simulate it is using variants
<laynor> same for the sum function.
<laynor> :-)
<Smerdyakov> There is no good way to write overloaded functions in OCaml.
<Smerdyakov> Variants are probably the best way to implement lists like you described, but you haven't given enough context for me to say for sure.
<laynor> I'm just exploring the language while studying programming language semantics, so the question is not in any context, it's just that I'm curious.. OCaml seems a good language to describe formal semantics, so I guess it could be a good language to use to implement new languages.. So comes my interest :)
Smerdyakov has quit ["BRB"]
<laynor> also, is there a way to detect integer overflow? I noticed that OCaml doesn't raise an exception.
<pango_> shadow operators with ones that detect overflows
<laynor> let (+) x y = let z = x + y in if (not x = (-y)) & z = 0 then raise IntegerOverflow else z
<laynor> something like that?
<pango_> in case of overflow the result won't be 0
<laynor> mhm, I recall that it printed 0 with printf yesterday, but I can be wrong. let me check
Smerdyakov has joined #ocaml
<pango_> there's an Overflow module in the Hump, but un-unusually, the page died
<laynor> :-/
twobitsprite has joined #ocaml
<laynor> pango_: mhm, i was wrong.
<twobitsprite> I'm working on ocamlyacc, and I get an error when compiling that says "Unbound type constructor sexpr" but I have a "type sexpr ..." in the %{ %} block... Its complaining about the "%type <sexpr> input" line
<twobitsprite> actually, it's complaining about the generated .mli file
<Smerdyakov> The code in that block doesn't go into the .mli file, I think.
<Smerdyakov> So you can't refer to it in %type directives.
<laynor> pango_: lol, yesterday it printed 0 just because I was testing with powers of 2..
<twobitsprite> Smerdyakov: er... so where should I specify it?
<Smerdyakov> Another .ml file.
<twobitsprite> ahh
eroyf has quit [Connection timed out]
<twobitsprite> how do you convert a char into a string?
<twobitsprite> seems like it should be just string_of_char... or at least listed in the "string conversion functions" section
<twobitsprite> ... or in the String module
ampex has quit []
<twobitsprite> hmm... actually... if I was working on a compiler which output ocaml code as a target language, would it just be easier to use camlp4?
<twobitsprite> instead of ocamlyacc/ocamllex and manually generating ocaml code
noteventime has quit ["Leaving"]
smimou has quit ["bli"]
fy__ has joined #ocaml
laynor has quit [Read error: 110 (Connection timed out)]
<Mr_Awesome> let char_of_string = String.make 1;;
<Mr_Awesome> i actually prefer haskell's way of handling strings as just a list of char's
spucky has joined #ocaml
<Mr_Awesome> hmm, perhaps that apostrophe wasnt a good idea there
<Mr_Awesome> but "chars" isnt a word. i just dont know
<mbishop> Doesn't SML use a vector of chars?
* mbishop looks at Smerdyakov for an answer
<Mr_Awesome> mbishop: you mean vector in the sense of array
<Mr_Awesome> ?
<mbishop> well, "vector" is the proper term for a single dimension matrix
<mbishop> but generally yes, vector is the same as array
pango_ has quit [Remote closed the connection]
pango_ has joined #ocaml
<spucky> I'm very new (as of about 10 minutes). How do I start cameleon?
<mbishop> I never did cameleon to build right
<spucky> I installed through Adept on Ubuntu, but I can't find the executable. I looked everywhere. I see an executable named "cameleon2.byte" in usr/bin
bluestorm_ has quit ["Konversation terminated!"]
<Ober> guess I bought the only book on ocaml :(
<mbishop> Which one is that?
<Ober> pratical ocaml
<Ober> il me lire francais au apprendre cette lang?
<Ober> if there's a better book in french I can do that
Smerdyakov has quit ["Leaving"]
Smerdyakov has joined #ocaml
pantsd has joined #ocaml
<buluca> what release is that in ubuntu?
<buluca> 1.9.13, same as debian :(
<spucky> 1.9.13 if you were asking me
Smerdyakov has quit ["Leaving"]
Smerdyakov has joined #ocaml
robyonrails has quit [Read error: 110 (Connection timed out)]
<mbishop> Ober: there are a few good french books about Ocaml
<mbishop> Ocaml for Scientists is a nice English one, a lot better than Practical OCaml heh
<Ober> ok
<Ober> looking for something for general purposes vs say math etc.
<mbishop> Well Ocaml for Scientists has quite a bit of math, but nothing like The Art of Computer Programming or anything heh
<Ober> yeah looking to replace my ruby prototypes :P
Smerdyakov has quit ["Leaving"]
<mbishop> Ocaml for Scientists is expensive though
piggybox has quit []
shawn has quit ["This computer has gone to sleep"]
<Ober> ahh
<Ober> online help looks goo
<Ober> good
piggybox_ has joined #ocaml
piggybox_ is now known as piggybox
spucky has quit [Remote closed the connection]
piggybox has quit ["Leaving"]
piggybox has joined #ocaml
thesoko has quit [Remote closed the connection]
thesoko has joined #ocaml
piggybox has quit [Read error: 104 (Connection reset by peer)]
piggybox has joined #ocaml
Smerdyakov has joined #ocaml
Smerdyakov has quit ["BRB"]
Smerdyakov has joined #ocaml
pants1 has joined #ocaml
pantsd has quit [Read error: 110 (Connection timed out)]
SmartIRC has joined #ocaml
SmartIRC has quit [Read error: 104 (Connection reset by peer)]
Smerdyakov has quit ["Leaving"]
robyonrails has joined #ocaml
Smerdyakov has joined #ocaml
love-pingoo has joined #ocaml
test1234 has joined #ocaml
ygrek has joined #ocaml
love-pingoo has quit ["Connection reset by pear"]
m3ga has joined #ocaml
test1234 has quit [Read error: 110 (Connection timed out)]
minciue has joined #ocaml
m3ga has quit ["disappearing into the sunset"]
bluestorm_ has joined #ocaml
shawn has joined #ocaml
Mr_Awesome has quit ["time to impregnate a moth"]
test1234 has joined #ocaml
noteventime has joined #ocaml
ygrek has quit []
thesoko has quit [Remote closed the connection]
thesoko has joined #ocaml
smimou has joined #ocaml
buluca has quit [Read error: 113 (No route to host)]
shawn has quit [Read error: 110 (Connection timed out)]
rwmjones_afk is now known as rwmjones
eroyf has joined #ocaml
Demitar has joined #ocaml
kniv7s has joined #ocaml
robyonrails has quit [Connection timed out]
laynor has joined #ocaml
pango_ has quit [Remote closed the connection]
pango_ has joined #ocaml
G has joined #ocaml
minciue has quit ["Ex-Chat"]
hsuh has joined #ocaml
<hsuh> hello ocamlers
<fremo> hello hsuh !
<hsuh> i need help with a little problem today :)
<fremo> go ahead ! :)
<hsuh> lets say i need to print numbers in the range 0 to n, randomly
<hsuh> but most importantly without repeating
<hsuh> i have two ideas: either use a hash to mark the numbers that have already been printed (i dont like this solution)
<fremo> true random ?
<hsuh> or make a list from 0 to n and then remove the sorted number from the list (but this would need some extra functions because array and list don't have remove, right ?)
<hsuh> no no
<hsuh> just the ordinary pseudo random.. no scientific work here.. just play
<rwmjones> hsuh, you want an "unsort" function
<rwmjones> xavierbot, restart
<xavierbot> Objective Caml version 3.10.0
<xavierbot> Camlp4 Parsing version 3.10.0
<hsuh> unsort, yes
<hsuh> good name
<rwmjones> just a sec, I have one
<hsuh> x*vierbot is so nice
<rwmjones> first define swap, like this:
<rwmjones> let swap xs i j = if i <> j then ( let c = xs.(i) in xs.(i) <- xs.(j); xs.(j) <- c ) ;;
<xavierbot> val swap : 'a array -> int -> int -> unit = <fun>
<rwmjones> then unsort for arrays is:
<rwmjones> let unsort_array xs = let n = Array.length xs in for i = 0 to n-2 do let j = Random.int (n - i) in swap xs i j done;;
<xavierbot> val unsort_array : 'a array -> unit = <fun>
<rwmjones> then unsort for lists is:
<rwmjones> let unsort xs = Array.to_list (unsort_array (Array.of_list xs)) ;;
<xavierbot> Characters 45-63:
<xavierbot> let unsort xs = Array.to_list (unsort_array (Array.of_list xs)) ;;
<xavierbot> ^^^^^^^^^^^^^^^^^^
<xavierbot> This expression has type unit but is here used with type 'a array
<rwmjones> oops, I mean:
<rwmjones> let unsort xs = let xs = Array.of_list xs in unsort_array xs; Array.to_list xs ;;
<xavierbot> val unsort : 'a list -> 'a list = <fun>
<rwmjones> then you need a range function:
<rwmjones> let rec range a b = if a <= b then a :: range (a+1) b else [] ;;
<xavierbot> val range : int -> int -> int list = <fun>
<rwmjones> range 0 10 ;;
<xavierbot> - : int list = [0; 1; 2; 3; 4; 5; 6; 7; 8; 9; 10]
<rwmjones> unsort (range 0 10) ;;
<xavierbot> - : int list = [0; 9; 6; 2; 5; 7; 3; 4; 1; 8; 10]
<rwmjones> unsort (range 0 10) ;;
<xavierbot> - : int list = [9; 3; 5; 7; 4; 0; 1; 2; 6; 8; 10]
<hsuh> rwmjones: thats exactly what i need... many thanks man
<fremo> nice
<rwmjones> it's not very efficient ... if you need speed, you could do better by taking the algorithm from unsort_array and applying it directly to an array
<hsuh> no, i just needed to unsort 400 elements for making a file for povray
<rwmjones> unsort (range 0 10) ;;
<xavierbot> - : int list = [8; 9; 0; 5; 7; 3; 4; 1; 6; 2; 10]
<rwmjones> I think there's a bug in that actually :-)
<rwmjones> unsort (range 0 10) ;;
<xavierbot> - : int list = [9; 7; 8; 4; 3; 2; 5; 6; 0; 1; 10]
<fremo> :)
<rwmjones> I think the end point of the iteration in unsort_array should be n-1 instead of n-2
<rwmjones> well, there you go, you can experiment :-)
<hsuh> of course!
<hsuh> let unsort_array xs = let n = Array.length xs in for i = 0 to n-1
<hsuh> do let j = Random.int (n - i) in swap xs i j done;;
<xavierbot> Characters 1-3:
<xavierbot> Parse error: illegal begin of top_phrase
<xavierbot> do let j = Random.int (n - i) in swap xs i j done;;
<xavierbot> ^^
<rwmjones> you have to paste it in as a single line, it's a pain
<hsuh> let unsort_array xs = let n = Array.length xs in for i = 0 to n-1
<hsuh> do let j = Random.int (n - i) in swap xs i j done;;let unsort_array xs = let n = Array.length xs in for i = 0 to n-1 do let j = Random.int (n - i) in swap xs i j done;;
<hsuh>
<xavierbot> Characters 1-3:
<xavierbot> Parse error: illegal begin of top_phrase
<xavierbot> do let j = Random.int (n - i) in swap xs i j done;;let unsort_array xs = let n = Array.length xs in for i = 0 to n-1 do let j = Random.int (n - i) in swap xs i j done;;
<xavierbot> ^^
<hsuh> let unsort_array xs = let n = Array.length xs in for i = 0 to n-1 do let j = Random.int (n - i) in swap xs i j done;;
<xavierbot> val unsort_array : 'a array -> unit = <fun>
<hsuh> ok
<rwmjones> hsuh, also, if you just redefine unsort_array, then you have to also redefine unsort, because otherwise unsort will continue to use the old definition
<rwmjones> that's the way ocaml works
<hsuh> let unsort xs = let xs = Array.of_list xs in unsort_array xs; Array.to_list xs ;;
<xavierbot> val unsort : 'a list -> 'a list = <fun>
<hsuh> unsort (range 0 10);
<rwmjones> unsort (range 0 10) ;;
<xavierbot> - : int list = [10; 9; 5; 4; 6; 3; 2; 1; 0; 8; 7]
<rwmjones> unsort (range 0 10) ;;
<xavierbot> - : int list = [10; 1; 8; 5; 6; 3; 2; 7; 0; 4; 9]
<rwmjones> heh, still wrong
<rwmjones> unsort (range 0 10) ;;
<xavierbot> - : int list = [10; 8; 0; 7; 2; 3; 4; 5; 6; 1; 9]
<hsuh> odd, my local version is working
<hsuh> or not
<hsuh> unsort(unsort(range 0 10));;
<xavierbot> - : int list = [9; 8; 2; 7; 10; 1; 3; 4; 0; 6; 5]
<hsuh> so ugly :)
<bluestorm_> hm
<bluestorm_> for i = 0 to n-1 do let j = Random.int (n - i) ...
<bluestorm_> why don't you use for i = n - 1 downto 0 ?
<fremo> let's do it with a tree now :)
Submarine has quit ["in Soviet Russia, Céline Dion owns you"]
<fremo> or a hashtable...
<fremo> no
EliasAmaral has joined #ocaml
thesoko has quit [Remote closed the connection]
thesoko has joined #ocaml
<hsuh> let unsort_array xs = let n = Array.length xs in for i = n-1 downto 0 do let j = Random.int (n - 0) in swap xs i j done;;
<xavierbot> val unsort_array : 'a array -> unit = <fun>
<hsuh> let unsort xs = let xs = Array.of_list xs in unsort_array xs; Array.to_list xs ;;
<xavierbot> val unsort : 'a list -> 'a list = <fun>
<hsuh> unsort (range 0 10);;
<xavierbot> - : int list = [4; 5; 9; 7; 3; 0; 10; 8; 2; 1; 6]
<hsuh> unsort (range 0 10);;
<xavierbot> - : int list = [6; 10; 0; 9; 1; 3; 2; 8; 4; 7; 5]
<hsuh> maybe we should not restrict the range of int which the Random.int can generate
<hsuh> it was Random.int (n-i) before
<hsuh> so the last elements could only be swapped with the nearest neighbors.. or something like that
piggybox has quit [Success]
yp3cjp has joined #ocaml
hsuh has quit [Remote closed the connection]
<bluestorm_> let unsort_array xs = let n = Array.length xs in for i = n-1 downto 0 do swap xs i (Random.int i) done;;
<xavierbot> val unsort_array : 'a array -> unit = <fun>
<bluestorm_> let unsort xs = let xs = Array.of_list xs in unsort_array xs; Array.to_list xs ;;
<xavierbot> val unsort : 'a list -> 'a list = <fun>
<bluestorm_> unsort (range 0 10);;
<xavierbot> Exception: Invalid_argument "Random.int".
<bluestorm_> :P
<bluestorm_> let unsort_array xs = let n = Array.length xs in for i = n-1 downto 1 do swap xs i (Random.int i) done; xs;;
<xavierbot> val unsort_array : 'a array -> 'a array = <fun>
<bluestorm_> unsort_array [|0;1;2;3;4;5;6;7;8;9|];;
<xavierbot> - : int array = [|5; 3; 7; 8; 6; 4; 9; 1; 0; 2|]
yp3cjp has quit ["Conscience doth make cowards of us all. -- Shakespeare"]
buluca has joined #ocaml
laynor has quit [Read error: 110 (Connection timed out)]
Naked has joined #ocaml
Naked is now known as Hadaka
<flux> fun
<flux> so the bot is in action and working good these days?
<flux> well, it's been only a bit more than a week I last time saw it ;)
<rwmjones> flux, it needs a patch so it strips "xavierbot," from expressions
<rwmjones> and also so it can handle private messages properly (at the moment it just ignores them)
piggybox has joined #ocaml
<flux> rwmjones, it would be fun if the let -definitions could be reviewed later
<flux> of course it might be difficult if the new definition is based on an older one..
<rwmjones> it would be nice if it could take multi-line definitions
<rwmjones> and do the right thing
<flux> hm, how? I don't think that's crucial for irc..
<rwmjones> let rec range a b =
<rwmjones> if a <= b then
<rwmjones> a :: range (a+1) b
<rwmjones> else
<rwmjones> []
<rwmjones> ;;
<xavierbot> Characters 2-4:
<xavierbot> Parse error: illegal begin of top_phrase
<xavierbot> ;;
<xavierbot> ^^
<flux> simply write it in a single line, no?
<rwmjones> you see it only sees the last line
<rwmjones> well yes, and that's what I do
<flux> much better for irc anyway
<rwmjones> but it's a bit tedious doing that with long definitions
<flux> do you have xclip installed?
<rwmjones> no, what's that?
<flux> it's a command line tool for manipulating X clipboard
<flux> I have a script based on that, called fixclip
<flux> it does: xclip -o | tr '\n' ' ' | sed 's/ */ /g' | xclip -i
<rwmjones> ah, nice :-)
<flux> so if I have a long piece of code in my clipboard, that will "ircify" it..
<rwmjones> well maybe that should be documented on the xavierbot page
<flux> oh, there's a page nowadays ;)
<rwmjones> yes, under et.redhat.com/~rjones/
test1234 has quit [Read error: 110 (Connection timed out)]
kniv7s has quit [Read error: 110 (Connection timed out)]
pango_ has quit [Remote closed the connection]
Smerdyakov has quit [Remote closed the connection]
minciue has joined #ocaml
pango_ has joined #ocaml
minciue has quit [Client Quit]
<Ober> hmm no aix support that could hamper me
duncanm has joined #ocaml
duncanm has left #ocaml []
laynor has joined #ocaml
minciue has joined #ocaml
piggybox_ has joined #ocaml
ulfdoz has quit [anthony.freenode.net irc.freenode.net]
piggybox has quit [anthony.freenode.net irc.freenode.net]
jeremiah has quit [anthony.freenode.net irc.freenode.net]
svenl has quit [anthony.freenode.net irc.freenode.net]
oracle1 has quit [anthony.freenode.net irc.freenode.net]
z__z has quit [anthony.freenode.net irc.freenode.net]
fean has quit [anthony.freenode.net irc.freenode.net]
mnemonic has quit [anthony.freenode.net irc.freenode.net]
kosmikus has quit [anthony.freenode.net irc.freenode.net]
kelaouchi has quit [anthony.freenode.net irc.freenode.net]
kosmikus has joined #ocaml
kelaouchi has joined #ocaml
ulfdoz has joined #ocaml
svenl has joined #ocaml
piggybox has joined #ocaml
z__z has joined #ocaml
fean has joined #ocaml
oracle1 has joined #ocaml
piggybox_ has quit ["Leaving"]
piggybox_ has joined #ocaml
piggybox has quit [SendQ exceeded]
mnemonic has joined #ocaml
Smerdyakov has joined #ocaml
piggybox_ is now known as piggybox
slipstream has quit [Read error: 104 (Connection reset by peer)]
ygrek has joined #ocaml
Submarine has joined #ocaml
leo037 has joined #ocaml
buluca has quit [Read error: 113 (No route to host)]
kniv7s has joined #ocaml
love-pingoo has joined #ocaml
postalchris has joined #ocaml
ygrek has quit []
kniv7s has quit [Read error: 104 (Connection reset by peer)]
kniv7s has joined #ocaml
oracle1 has quit [anthony.freenode.net irc.freenode.net]
fean has quit [anthony.freenode.net irc.freenode.net]
z__z has quit [anthony.freenode.net irc.freenode.net]
buluca has joined #ocaml
buluc1 has joined #ocaml
buluca has quit [Client Quit]
z__z has joined #ocaml
fean has joined #ocaml
oracle1 has joined #ocaml
minciue has quit [Read error: 104 (Connection reset by peer)]
z__z has quit [Remote closed the connection]
z__z has joined #ocaml
buluc1 is now known as buluca
david_koontz has joined #ocaml
Lena has joined #ocaml
kniv7s has quit ["me ne vo'"]
z__z has quit [Remote closed the connection]
noteventime has quit [Remote closed the connection]
z__z has joined #ocaml
noteventime has joined #ocaml
robyonrails has joined #ocaml
slipstream has joined #ocaml
buluca has quit [Read error: 113 (No route to host)]
laynor has quit [Read error: 110 (Connection timed out)]
ppsmimou has quit [Read error: 110 (Connection timed out)]
gim has quit [Read error: 110 (Connection timed out)]
buluca has joined #ocaml
z__z has quit [Read error: 110 (Connection timed out)]
Mr_Awesome has joined #ocaml
gim has joined #ocaml
z__z has joined #ocaml
ppsmimou has joined #ocaml
Lena has quit ["Leaving."]
test1234 has joined #ocaml
pants1 has quit [Read error: 110 (Connection timed out)]
piggybox has quit [Read error: 110 (Connection timed out)]
test1234 has quit [Read error: 110 (Connection timed out)]
thesoko has quit [Remote closed the connection]
thesoko has joined #ocaml
screwt8 has quit [Read error: 104 (Connection reset by peer)]
pantsd has joined #ocaml
screwt8 has joined #ocaml
Submarine has quit ["in Soviet Russia, Céline Dion owns you"]
buluca has quit [Read error: 113 (No route to host)]
robyonrails has quit [Connection timed out]
robyonrails has joined #ocaml
jeremiah has joined #ocaml
screwt8 has quit [Read error: 104 (Connection reset by peer)]
screwt8 has joined #ocaml
piggybox has joined #ocaml
Gabriell has quit [Read error: 110 (Connection timed out)]
visage has joined #ocaml
robyonrails has quit ["me ne vo'"]
leo037 has quit [Remote closed the connection]
fy__ has quit [Read error: 110 (Connection timed out)]
pantsd has quit [Read error: 110 (Connection timed out)]
postalchris has quit [Read error: 110 (Connection timed out)]
qwwqe has quit ["Leaving"]
EliasAmaral has quit [Remote closed the connection]
buluca has joined #ocaml