smimram has quit [Read error: 110 (Connection timed out)]
madroach has quit [Remote closed the connection]
seafood_ has joined #ocaml
wy has quit [Remote closed the connection]
lbc has left #ocaml []
lbc has joined #ocaml
wy has joined #ocaml
<fbvortex>
is there a way to simultaneously define recursive and non-recursive bindings simultaneously using the "and" keyword? it seems that the and puts the following binding the same recursion category as the let that preceded it.
wy has quit ["Ex-Chat"]
<fbvortex>
or alternately, is there any reason why all lets shouldn't be of the "let rec" variety?
Jeff_123 has joined #ocaml
<pango>
shadowing
<fbvortex>
pango: can you explain what you mean?
<Jeff_123>
Yoric, you here?
<pango>
using a non recursive binding, you can shadow a binding on purpose
<pango>
that's sometimes useful, if not always a very good style (can be confusing)
<fbvortex>
so suppose i want to do several let bindings at the same scoping level, some recursive and others not; if I'm not trying to use shadowing, then is it OK style to make the first one a let rec and just use the "and" keyword for the following bindings?
<Smerdyakov>
fbvortex, he meant something like this:
<pango>
sure
<Smerdyakov>
let x = 1 in
wy has joined #ocaml
<Smerdyakov>
let x = x + 1 in
<Smerdyakov>
let x = x * 2 in
<Smerdyakov>
etc.
<Jeff_123>
I do that sometimes, but it's probably not good practice
<fbvortex>
OK, I get it now.
<Smerdyakov>
I consider it great practice.
<Smerdyakov>
If you make up new names, it can be hard to keep track of which version you're using.
<fbvortex>
to me, it seems like it would be nice for clarity if "and" explicitly allowed the use of rec to control whether the next binding is a recursive one or not
<Jeff_123>
it can be ok, but if you're doing a whole lot with one name you have to be careful to remember exactly what it ended up as. Not a big deal, just you have to be careful.
<Smerdyakov>
fbvortex, that is very rarely useful.
<Smerdyakov>
fbvortex, you just use successive distinct 'let's for a sequence of non-recursive bindings, and you rarely want to mix recursive with non-recursive in practice.
<Yoric[DT]>
Jeff_123: I'm here.
<Yoric[DT]>
Just falling asleep.
<fbvortex>
Smerdyakov: but "and" works whether the preceding let was recursive or not.
<Smerdyakov>
fbvortex, right, but I usually wince when I see someone use 'and' with non-recursive 'let'.
<fbvortex>
Smerdyakov: I don't understand why that is wince-worthy...
<Smerdyakov>
fbvortex, it has no useful function (beyond syntactic sugar) to serve for non-recursive bindings, so I associate it with recursion. To verify if it's being used recursively or not, you need to look back past arbitrarily much code.
<Yoric[DT]>
Well, I'm going to fall asleep any second now.
<Yoric[DT]>
So good night everyone.
Yoric[DT] has quit ["Ex-Chat"]
<fbvortex>
Smerdyakov: in a function definition, if I just do successive lets, I get a syntax error. How is this done without the use of 'and'?
wy has quit [Remote closed the connection]
<Smerdyakov>
fbvortex, I showed you in my example above. You're forgetting 'in'.
wy has joined #ocaml
<fbvortex>
Smerdyakov: but that implies the preceding definition is in a higher scoping level than the succeeding one. If they are logically at the same scoping level, doesn't the 'and' cleanly indicate that?
<Smerdyakov>
fbvortex, this is a problem that an auto-indenter solves easily. I don't see any practical problem.
<Jeff_123>
noooo yoric tell us all about camlp4!
hkBst has quit ["Konversation terminated!"]
<fbvortex>
Smerdyakov: implementation-wise, the 'and' construct is equivalent to an 'in let' declaration?
ser_ has joined #ocaml
ser_ has quit [Remote closed the connection]
<Smerdyakov>
fbvortex, yes.
ser_ has joined #ocaml
ser_ has quit [Client Quit]
<Jeff_123>
except it goes both ways
wy has quit [Remote closed the connection]
wy has joined #ocaml
wy has quit [Remote closed the connection]
wy has joined #ocaml
ita has quit ["Hasta luego!"]
centrinia has joined #ocaml
<centrinia>
If I had a sum type with no constructors, how do I define a mutable value of that type?
<centrinia>
Wait, how do I construct an abstract type?
Associat0r has joined #ocaml
wy has quit [Remote closed the connection]
wy has joined #ocaml
wy has quit [Remote closed the connection]
wy has joined #ocaml
<centrinia>
Okay, I solved my problem: not using abstract types with camlidl.
Torment has quit [Read error: 104 (Connection reset by peer)]
smimou has quit ["bli"]
kmeyer has quit ["Leaving"]
centrinia has quit ["Ex-Chat"]
Jedai has joined #ocaml
wy has quit [Remote closed the connection]
wy has joined #ocaml
wy has quit [Client Quit]
wy has joined #ocaml
dbueno has joined #ocaml
qpu has joined #ocaml
qpu has quit []
jlouis_ has quit [Remote closed the connection]
jlouis has joined #ocaml
Jeff_123 has quit ["Leaving."]
jlouis has quit [Remote closed the connection]
qpu has joined #ocaml
nuncanada has quit [Remote closed the connection]
qpu has quit []
dbueno has quit ["This computer has gone to sleep"]
kmeyer has joined #ocaml
<context>
mmm so their are ruby heads looking at caml beside me
seafood_ has quit [Read error: 110 (Connection timed out)]
qpu has joined #ocaml
delamarche has quit []
qpu has quit []
qpu has joined #ocaml
Jedai has quit [calvino.freenode.net irc.freenode.net]
pippijn has quit [calvino.freenode.net irc.freenode.net]
__suri has quit [calvino.freenode.net irc.freenode.net]
seafood has quit [calvino.freenode.net irc.freenode.net]
rogo has quit [calvino.freenode.net irc.freenode.net]
Oatskool has quit [calvino.freenode.net irc.freenode.net]
mattam has quit [calvino.freenode.net irc.freenode.net]
lbc has quit [calvino.freenode.net irc.freenode.net]
richardw has quit [calvino.freenode.net irc.freenode.net]
bebui has quit [calvino.freenode.net irc.freenode.net]
Jedai has joined #ocaml
lbc has joined #ocaml
pippijn has joined #ocaml
__suri has joined #ocaml
seafood has joined #ocaml
Oatskool has joined #ocaml
rogo has joined #ocaml
bebui has joined #ocaml
richardw has joined #ocaml
mattam has joined #ocaml
jonathanv has joined #ocaml
jonafan has quit [Read error: 110 (Connection timed out)]
wy has quit ["Ex-Chat"]
wy has joined #ocaml
wy has quit [Remote closed the connection]
wy has joined #ocaml
wy has quit [Client Quit]
wy has joined #ocaml
wy has quit [Remote closed the connection]
wy has joined #ocaml
wy has quit [Remote closed the connection]
wy has joined #ocaml
wy has quit ["Ex-Chat"]
wy has joined #ocaml
wy has quit [Client Quit]
ttamttam has joined #ocaml
wy has joined #ocaml
Tov_enst has quit ["Ex-Chat"]
mrsolo has joined #ocaml
ygrek has joined #ocaml
pango has quit [Excess Flood]
pango has joined #ocaml
mrsolo_ has joined #ocaml
mrsolo has quit [Read error: 113 (No route to host)]
<wy>
Hi
Jeff_123 has joined #ocaml
<fbvortex>
So, within a module, if I make a module with a functor, what name do I need to use to access the functor-generated module's code? For example, within one of my modules I use module Blah = Somelibrary.Make(int) . Within the module where Blah is declared, I try to use Blah.function and I get "unbound value Blah.function"; however, if I do those steps in the interpreter, the same syntax works...
wy has quit ["Leaving"]
<Jeff_123>
hm, i'm not sure I understand. You are doing something like module Blah = struct ... Blah.function ... end ?
<Jeff_123>
ooooh
<Jeff_123>
well if you send Blah to the toplevel, you can use it anywhere, including a new binding of Blah
<Jeff_123>
does that help?
Tetsuo has joined #ocaml
<fbvortex>
Jeff_123: actually, I was using it correctly, it turned out to be a typo. I was just concerned because this is the first time I'm messing with functors, so I thought maybe I was doing something wrong.
<fbvortex>
thanks for the help though.
<Jeff_123>
yer welcome
<context>
ocaml has no sense of 'return' right?
<Jeff_123>
it's implicit
<context>
jeff_123: srry im new to ocaml, im a heavy believer in returning early and getting rid of useless else {} blocks :x
<context>
ocaml is kind of throwing me through a loop in how to work with it :p
<context>
jeff_123: id rather if(something){...; return;} ....; return;
<context>
as appose to if(){...}else{...}
<Jeff_123>
you can do that sort of thing in caml
<fbvortex>
context: if you have a value you want to return, then you implicitly return it before the else
<Jeff_123>
"if x=y then 1 else 2"
<context>
at the end of the fucnction
<context>
meh ill keep playing around
<context>
i have much more to read im sure
<Jeff_123>
well I guess the question would be where do you want to return that caml isn't letting you, and then maybe there's some technique we could show you :)
<fbvortex>
context: you can only have one return type though, so if you want to "abort" without return anything, you can always supply an exception, or if your function is going to just return unit, then supply that right away
<fbvortex>
context: you probably won't "get it" until you start playing with some code in the interpreter
<Jeff_123>
One of my favorite things ML lets you do is conditional bindings.... "let x = if y=0 then "something" else "something else" in ..."
<context>
fbvortex: yeah thats what i need to start doing ;)
<context>
every language after php and c was like ok, thnx, ocaml kinda throws me through a loop
<flux>
pattern matching with guards would allow something like "return early"
<flux>
albeit I don't know if it's good style; depends on the case I suppose
<Jeff_123>
its' good style
<Jeff_123>
match x with 'a' -> 1 | 'b' -> 2 'c' -> 3 ... (yes I know you can just use int_of_char)
<context>
or maybe functions inside of function, and a simple if/else
<context>
to call them
<context>
i guess
<context>
done within reason anyway
<Jeff_123>
the syntax of caml really makes it tough to do something a bad way as long as you stick to functional programming
<Jeff_123>
if you're worried about guards you can always give a last default case of | _ -> invalid_arg "shouldnt' see this"
<context>
yeah
<context>
are there any recommended books for a technical person to learn ocaml
<context>
everything im reading online is kind of fluff
<flux>
context, did you try the ocaml book online?
<context>
they show a bunch of usage of _ without telling me what exactly it is
<Jeff_123>
oh hehe, I think I might remember you from a couple nights ago
<context>
jeff_123: ;)
<context>
probably
<Jeff_123>
_ matches anything
<context>
so how the hell does: let _ = work :x
<context>
is that kinda sorta like main() or if __FILE__ == $0
<Jeff_123>
_ is different syntax there, it's a throwaway binding
<context>
jeff_123: ;) thats where i get confused.
<Jeff_123>
it's the same as ignore (do_something)
<context>
i see _ i wanna know what exactly it is
<context>
ass appose to "we'll tell you a little now, a little later"
<Jeff_123>
_ can be used in pattern matching, eg in the declaration of a function or in match ...with...
<Jeff_123>
or _ can be used in the place of a binding, to say "dont bind the result"
<context>
i usually learn by example, maybe i should stop looking at other caml code, haha
<xavierbot>
Parse error: illegal begin of top_phrase
<rwmjones>
open Printf;;
<rwmjones>
xavierbot, restart !
<xavierbot>
<xavierbot>
Objective Caml version 3.10.0
<xavierbot>
Camlp4 Parsing version 3.10.0
<rwmjones>
open Printf ;;
<rwmjones>
printf "hello\n";;
<xavierbot>
hello
<xavierbot>
- : unit = ()
<Jeff_123>
oh it's using camlp4 parsing? Why does it need double ;; then?
* context
sets up
<rwmjones>
`;;' just marks the end of the phrase
<context>
jeff_123: prolly to not spam channel all day long
<Jeff_123>
so hm
<rwmjones>
it uses camlp4 to remove certain unsafe parts of the language
<Jeff_123>
do {print_endline "one"; print_endline "two"}
<Jeff_123>
oops
<Jeff_123>
do {print_endline "one"; print_endline "two"};;
<xavierbot>
Characters 1-3:
<xavierbot>
Parse error: illegal begin of top_phrase
<xavierbot>
do {print_endline "one"; print_endline "two"};;
<xavierbot>
^^
<Jeff_123>
ok so it's not really revised syntax
<rwmjones>
no it's camlp4o
* context
kicks openbsd in the head
<Jeff_123>
um, I assume it's hardened against like, "while true do print_endline "" done"
<Jeff_123>
i'm tempted to try but I don't wanna be banned :)
<rwmjones>
it has some flood protection
<context>
while true do 1+1 done ?
<rwmjones>
iirc it won't print more than 10 lines of output from a command
<Jeff_123>
ah that's good
<context>
it will cause the bot to timeout
<rwmjones>
& it uses rlimits to limit amount of cpu/memory/etc
<Jeff_123>
load nums.cma;;
<xavierbot>
Characters 1-5:
<xavierbot>
load nums.cma;;
<xavierbot>
^^^^
<xavierbot>
Unbound value load
<Jeff_123>
#load "nums.cma";;
<Jeff_123>
ha, figures
<context>
is camlp4 included in caml ?
<context>
#use "topfind";;
<Jeff_123>
yup it is
<context>
kk
<Jeff_123>
I've wanted to learn it but... ya. I've gotten as far as learning the revised syntax. I wish tuareg-mode handled it.
<Jeff_123>
but the syntax extentions for creating parsers etc... nope :(
filp has joined #ocaml
<context>
ahh yeah
<context>
rwmjones: do you know how to define methods that allow printf() style params
<context>
maybe i wouldnt need it but :/
<Jeff_123>
printf is a hack
<Jeff_123>
if yuo need a function that takes an arbitrary number of arguments what you want is probably a list
<Jeff_123>
type opt = Yes | No;;
<xavierbot>
type opt = Yes | No
<Jeff_123>
type print = String of string | Int of int;;
<xavierbot>
type print = String of string | Int of int
<Jeff_123>
let print = List.iter (function String s -> print_string s | Int i -> print_int i);;
<xavierbot>
val print : print list -> unit = <fun>
<rwmjones>
context, you can't in pure ocaml
<Jeff_123>
print [String "hello "; Int 1; String " person\n"];;
<xavierbot>
hello 1 person
<xavierbot>
- : unit = ()
<Jeff_123>
that's kind of like printf, except proper :)
<context>
grrrrrr
<context>
figures
* context
beats openbsd with a stick
<Jeff_123>
dude, don't you know that hitting openbsd only hurts yourself? it's hardened and all that
<Jeff_123>
here's a project for you. this one sounds fun
<context>
i <3 openbsd
<context>
id prefer gentoo, but no dc allows it by default
<Jeff_123>
a function that takes a string and a map of strings to integers, strings etc
<Jeff_123>
the string coiuld be like
<Jeff_123>
"%s{name}'s phone number is %i{phonenumber}."
<Jeff_123>
and then substituted in the right values from the map
<Jeff_123>
sorta like tcl substitution
<context>
mmm
<context>
good templating
<context>
thnx ;)
<Jeff_123>
yer welcome :D
jonafan has joined #ocaml
<context>
should i email it to you when it works, aha ;)
Proteus has quit ["Leaving"]
Jeff_123 has quit [Read error: 110 (Connection timed out)]
smimou has joined #ocaml
jonathanv has quit [Read error: 110 (Connection timed out)]
Yoric[DT] has joined #ocaml
<Yoric[DT]>
hi
hkBst has joined #ocaml
<context>
ocaml's INSTALL file is worthless :/ it actually requires reading for the smart people :(
<context>
openbsd fails !
<context>
time to find a new dc
<context>
if i ever open a datacenter
<context>
first ruel
<context>
we will NOT support redhat or mandrake
<context>
and maybe not debian
<context>
and if you want openbsd dont complain about packaging
<Yoric[DT]>
Debian ?
<Yoric[DT]>
sudo apt-get install ocaml
<context>
but it debian
<context>
:p
<context>
support more, and support less of more i guess
<context>
so debian and redhat are fine
<context>
just dont complain later
cygnus_ has quit [calvino.freenode.net irc.freenode.net]
Demitar has quit [calvino.freenode.net irc.freenode.net]
<context>
>> Fatal error: Ocaml and preprocessor have incompatible versions
<context>
WHY !
Demitar has joined #ocaml
cygnus_ has joined #ocaml
<context>
i dont expect anyone to answer that
<context>
ill figure it out in the morning
<Yoric[DT]>
good luck
Yoric[DT] has quit ["Ex-Chat"]
seafood_ has joined #ocaml
seafood_ has quit []
ertai has joined #ocaml
wy has joined #ocaml
Tetsuo has quit [Read error: 110 (Connection timed out)]
seafood_ has joined #ocaml
wy has quit ["Ex-Chat"]
Tetsuo has joined #ocaml
ertai has quit ["leaving"]
ertai has joined #ocaml
ertai has quit [Client Quit]
qpu has quit ["kthxbye"]
ertai has joined #ocaml
nuncanada has joined #ocaml
nuncanada has quit [Read error: 104 (Connection reset by peer)]
hkBst_ has joined #ocaml
hkBst has quit [Connection timed out]
buluca has joined #ocaml
marmottine has joined #ocaml
Jedai has quit [Read error: 104 (Connection reset by peer)]
Jedai has joined #ocaml
dbueno has joined #ocaml
bongy has joined #ocaml
hkBst_ is now known as hkBst
appletizer has joined #ocaml
appletizer has left #ocaml []
smimram has joined #ocaml
smimou has quit [Read error: 110 (Connection timed out)]
seafood_ has quit []
Jeff_123 has joined #ocaml
<Jeff_123>
hey context, you still here?
pango has quit [Remote closed the connection]
asmanur has joined #ocaml
pango has joined #ocaml
bluestorm_ has joined #ocaml
RobertFischer has joined #ocaml
bongy has quit ["Leaving"]
bongy has joined #ocaml
Jeff_123 has quit ["Quit"]
jonafan has quit [Read error: 104 (Connection reset by peer)]
filp has quit ["Bye"]
jcpiza has joined #ocaml
jonathanv has joined #ocaml
jonathanv is now known as jonafan
rayno has joined #ocaml
ertai has quit ["leaving"]
ttamttam has left #ocaml []
gaja has quit ["leaving"]
gaja has joined #ocaml
bongy has quit [Remote closed the connection]
bongy has joined #ocaml
denbuen_ has joined #ocaml
madroach has joined #ocaml
dbueno has quit [Read error: 110 (Connection timed out)]
Tetsuo has quit [Remote closed the connection]
ertai has joined #ocaml
ttamttam has joined #ocaml
filp has joined #ocaml
asmanur has quit [Read error: 110 (Connection timed out)]
rwmjones has quit ["Closed connection"]
asmanur has joined #ocaml
buluca has quit [Read error: 110 (Connection timed out)]
<jonafan>
asdf
<RobertFischer>
jkl;
wy has joined #ocaml
asmanur has quit [Remote closed the connection]
Yoric[DT] has joined #ocaml
<Yoric[DT]>
hi
RobertFischer has left #ocaml []
wy has quit [Read error: 104 (Connection reset by peer)]
RobertFischer has joined #ocaml
rayno has quit [Connection timed out]
ygrek has quit [Remote closed the connection]
jlouis has joined #ocaml
<jcpiza>
hi people
<RobertFischer>
Hey.
<jcpiza>
i've a question about ocaml/caml-light
<jcpiza>
caml-light is not supported in x86-64, right?
<RobertFischer>
No clue.
<jcpiza>
what is the RAM peak that uses ocaml?
<jcpiza>
16 MB peak?
<RobertFischer>
For the VM?
<jcpiza>
yes, VM of Ocaml
<RobertFischer>
I'm not positive. I'd guess that the VM itself kicks around at less than 32 MB.
<RobertFischer>
In that I have memory-light applications that run in less than that much space.
<jcpiza>
i'd readed that the VM of caml-light uses 32-10=22 bits for any data, and 10 bits for tags.
<RobertFischer>
K.
<hcarty>
OCaml uses 31bit integers on 32bit systems, or 63 for 64 bit systems
<jcpiza>
22 bit means 2^22 word32 = 4 MiWord = 16 MiB.
<jcpiza>
why ocaml is limited to 16 MiB on 64 bit x64-64?
<madroach>
I don't think the memory usage of ocaml is mainly caused by tag overhead. Maybe for linked lists and the like.
<madroach>
what?
<madroach>
who says so?
<jcpiza>
i
<mbishop>
strings are limited to 16MB
<hcarty>
jcpiza: I run OCaml programs quite regularly which us 600-700megabytes of RAM
<jcpiza>
i proved that succ(succ(succ(.....0))....) was crashed
<mbishop>
but that is a limit which is quite prevelant in most languages
<jcpiza>
although ulimit -s was high
<jcpiza>
hcarty: what says this command succ(100000) ; ?
<jcpiza>
it will be 100001 or crash?
<hcarty>
# succ(100000);;
<hcarty>
- : int = 100001
<jcpiza>
hcarty: and succ(10000000) ; ?
<hcarty>
Same + 1
<jcpiza>
hcarty: and succ(1000000000) ; ?
<mbishop>
Integer literal exceeds the range of representable integers of type int
<hcarty>
That one works for me as well
<hcarty>
On 32bit OCaml 3.10.0
<mbishop>
OCaml 3.09.2 gives me the above
<mbishop>
does 3.10 do automatic bigint or something?
<hcarty>
The toplevel still says it is type int
<hcarty>
# succ(1000000000);;
<hcarty>
- : int = 1000000001
<mbishop>
huh, weird
<hcarty>
# max_int;;
<hcarty>
- : int = 1073741823
<mbishop>
oh I think I added one too many zeros :)
<hcarty>
Yeah, just one more would do it
<jcpiza>
hcarty, iterative succ is not valid, i want recursive succ
<hcarty>
jcpiza: Anything recursive function which is not tail recursive can cause problems with large enough values
<jcpiza>
let rec succ n = if n = 0 then 1 else 1 + succ (n - 1 ) ;;
<xavierbot>
val succ : int -> int = <fun>
<jcpiza>
try again
<jcpiza>
succ(2000000000) ;;
<xavierbot>
Out of memory during evaluation.
<jcpiza>
succ(1000000000) ;;
<xavierbot>
Out of memory during evaluation.
<jcpiza>
succ(100000000) ;;
<xavierbot>
Out of memory during evaluation.
Jeff_123 has joined #ocaml
<jcpiza>
succ(10000000) ;;
<xavierbot>
Out of memory during evaluation.
<hcarty>
jcpiza: We get the point
<mbishop>
works fine for me, actually
<jcpiza>
succ(100000) ;;
<xavierbot>
Out of memory during evaluation.
<Jeff_123>
howdy!
<mbishop>
# let succ_rec n = if n = 0 then 1 else 1 + succ (n - 1);;
<mbishop>
val succ_rec : int -> int = <fun>
<jcpiza>
argghhhh!!!
<mbishop>
# succ_rec 1000000000;;
<mbishop>
- : int = 1000000001
<mbishop>
# succ_rec 10000000000;;
<mbishop>
Integer literal exceeds the range of representable integers of type int
<hcarty>
mbishop: Exactly :-)
<jcpiza>
succ(50000) ;;
<xavierbot>
Out of memory during evaluation.
<jcpiza>
succ(1000) ;;
<xavierbot>
- : int = 1001
marmottine has quit ["Quitte"]
<jcpiza>
succ(10000) ;;
<xavierbot>
- : int = 10001
<jcpiza>
succ(40000) ;;
<xavierbot>
Out of memory during evaluation.
<jcpiza>
succ(20000) ;;
<xavierbot>
- : int = 20001
<jcpiza>
i dislike ocaml
<Jeff_123>
You guys are doing something very strange
<mbishop>
jcpiza: why is that?
<Jeff_123>
I just got here, but I can tell it's probably some develish plot against xavierbot.
<jcpiza>
stack very small
<bluestorm_>
jcpiza:
<mbishop>
xavierbot isn't even real ocaml :)
<hcarty>
Jeff_123: A cruel fate for such a noble bot
<bluestorm_>
let succ = let rec succ acc = function 0 -> acc | n -> succ (acc + 1) (n - 1) in succ 0;;
<xavierbot>
val succ : int -> int = <fun>
<bluestorm_>
succ 40000;;
<xavierbot>
- : int = 40000
<bluestorm_>
let succ = let rec succ acc = function 0 -> acc | n -> succ (acc + 1) (n - 1) in succ 1;;
<xavierbot>
val succ : int -> int = <fun>
<bluestorm_>
succ 40000;;
<xavierbot>
- : int = 40001
<bluestorm_>
succ 400000;;
<xavierbot>
- : int = 400001
<bluestorm_>
succ 4000000;;
<xavierbot>
- : int = 4000001
<bluestorm_>
jcpiza: is that better ?
<jcpiza>
if ocaml can't work with many recursive functions then it craps me.
<bluestorm_>
he can
<Jeff_123>
phew! Now it's happy with tail recursion.
<bluestorm_>
but the bytecode interpreter has a stack-size limit
<bluestorm_>
(wich you can change)
<jcpiza>
why this limit?
<mbishop>
Jeff_123: weird, since even the non tail recursive version works just fine in my toplevel
<bluestorm_>
jcpiza: if you want to use _huge_ recursive calls, use tail-recursion
<Jeff_123>
from what I heard, xavierbot has strict limits on how much CPU and memory it can use.
<bluestorm_>
this is not ocaml-specific
filp has quit ["Bye"]
<bluestorm_>
you'll have to handle that in any language
<bluestorm_>
(and the tail-recursion support in ocaml is particulary good)
<Jeff_123>
try doing deep recursion in tcl - it's horrible at it!
<mbishop>
TCO is guranteed in ocaml isn't it? (if only because htere is one implementation)
<Jeff_123>
as in - don't do it
<jonafan>
or in c
<mbishop>
there*
<jcpiza>
bluestorm_, don't be made the work of tail-recursion by ocaml instead by human?
<bluestorm_>
?
<bluestorm_>
hm
<bluestorm_>
jcpiza: the compiler can't do that most of the time
<bluestorm_>
and no compiler do that
<bluestorm_>
in any language
<jcpiza>
scheme does
<bluestorm_>
you have to use tail-recursion yourself
<bluestorm_>
jcpiza: do you have any evidence of that ?
<bluestorm_>
i don't think so
wy has joined #ocaml
<bluestorm_>
most compilers _optimize_ tail-recursion to a simple loop, when it is found (OCaml does, and most scheme compiler certainly do)
<jcpiza>
lisp does too
<Jeff_123>
ocaml does tail recursion when 1. the recursion does not occur within try...with, and 2. at the end of the recursion the function returns immediately (ie no stack rewinding necessary)
<bluestorm_>
but transforming a non-tail-recursive function into a tail-recursive one seems difficult
<bluestorm_>
actually, i don't think it's generally possible
<bluestorm_>
so i don't see your point here
<jonafan>
Jeff_123, tail recursion can't work with try...with? if you call a tail recursive function within a try...with block it won't run tail recursively?
<jcpiza>
the above succ doesn't use try .. with
<bluestorm_>
jonafan: yes it will
<jonafan>
ok good
<bluestorm_>
but for example
<madroach>
but the succ does a 1+succ
<bluestorm_>
let foo = function 0 -> () | n -> try foo (n - 1) with _ -> ()
<bluestorm_>
is not tail recursive
<jonafan>
ah okay
<jonafan>
that makes more sense
<bluestorm_>
jcpiza: your function was not tail recursive
<cygnus_>
isn't it ?
<Jeff_123>
right, that's not tail recursive
<cygnus_>
why isn't it tail recursive
<cygnus_>
the function is called last
<bluestorm_>
cygnus_: because try... with use an exception handler
<cygnus_>
ok
<bluestorm_>
i don't know the precise implementation, some wise guy may explain you better, but that's the ide
<bluestorm_>
a
<Jeff_123>
it's because the point of tail recursion is to use a constant stack size. when you're telling ocaml to expect any exceptions it has to store each recursive call in case there's an exception so it can rewind the stack
<bluestorm_>
anyway, using a try..with in _each_ recursive call is a bad idea
<bluestorm_>
most of the case what you really want to do is
<bluestorm_>
let foo = let rec foo_aux = ... in try foo_aux () with <exception handling>
<bluestorm_>
where foo_aux is tail-recursive
<jcpiza>
is tail-recursive fibonacci ?
<madroach>
no
<Jeff_123>
it can be, but it's harder than then "normal" way
<jonafan>
the simple one isn't because the last operation is +
<madroach>
actually there are formulae to compute the fibonaccis without recursion/iteration
<jonafan>
let rec fib n = if n = 1 then 1 else fib (n-1) + fib (n-2);; <--- + happens last
<bluestorm_>
jonafan: there has to be only one call
<xavierbot>
This expression has type float but is here used with type int
<jcpiza>
fib(10001)-.fib(10000);;
<xavierbot>
- : float = nan
<jcpiza>
Not A Number? Why?
<bluestorm_>
jcpiza: if you're interested in exact arithmetic on big numbers
<bluestorm_>
you should use a dedicated library
<bluestorm_>
floats and ints are the usual one
<jonafan>
nums.cma
<jonafan>
use that one
<jcpiza>
i'm using small numbers, less than 6 digits
<bluestorm_>
fib(10000) isn't a small number
<bluestorm_>
who are you trying to joke at ?
<madroach>
jcpiza: are you actually trolling or what?
<jonafan>
can you load stuff here?
<jonafan>
#load "nums.cma";;
<bluestorm_>
i don't think so
<jonafan>
let x = Int 1;;
<xavierbot>
Characters 13-14:
<xavierbot>
let x = Int 1;;
<xavierbot>
^
<xavierbot>
Unbound constructor Int
<Jeff_123>
nope
<jonafan>
looks like no
<jcpiza>
madroach, ocaml craps me.
<bluestorm_>
xavierbot is pretty paranoid on such things
<jonafan>
yeah
<jonafan>
probably for the best
<bluestorm_>
jcpiza: but what you said for now was even crappier
<bluestorm_>
no sane person would evaluate a language with fibonnaci
<bluestorm_>
of course you might have other points, more interesting, wich you have not told yet
<bluestorm_>
but "hehe i can blow up the stack with a big recursive function" is not really good
ttamttam has left #ocaml []
<jcpiza>
if ocaml has big machine like x86-64, why can't compute big numbers or big functions?
<Jeff_123>
um, it can
<bluestorm_>
jcpiza: you have libraries dedicated to exact arithmetic on big numbers
<jcpiza>
and deeper recursive functions, how?
<bluestorm_>
you can use "int" up to 2^62, wich is not that bad
<bluestorm_>
jcpiza: there is a OS limit anyway
<bluestorm_>
depends on what the function does, and the limit may be higher on 64-bits-aware OSes
<jcpiza>
bluestorm_, i did put ulimit -s to max. and it was not a OS limit
<madroach>
bluestorm, does ocaml use the OS stack?
<bluestorm_>
madroach: it does with ocamlopt
<bluestorm_>
(native-code compiler)
<bluestorm_>
ocamlc use the VM limit
<jcpiza>
where is the limit that ocaml did put?
<bluestorm_>
wich is lower, of course
<madroach>
so with bc I could achieve deeper recursions. Nice.
desp has joined #ocaml
<desp>
Hi.
<Jeff_123>
howdy
<desp>
Can someone here give an opinion on Appel's "Modern Compiler Implementation in ML"? I thought to buy it, but there are some unfavorable reviews on Amazon.
<madroach>
salve!
<Jeff_123>
64L;;
<xavierbot>
- : int64 = 64L
<bluestorm_>
desp: Smerdyakov seems to like it
<Jeff_123>
1000000000000000000L;;
<xavierbot>
- : int64 = 1000000000000000000L
qwr has quit [calvino.freenode.net irc.freenode.net]
Hadaka has quit [calvino.freenode.net irc.freenode.net]
flux has quit [calvino.freenode.net irc.freenode.net]
<Jeff_123>
Int64.max_int;;
<xavierbot>
- : int64 = 9223372036854775807L
<jcpiza>
let rec succ n = if n = 0L then 1L else 1L + succ (n - 1L) ;;
<xavierbot>
Characters 41-43:
<xavierbot>
let rec succ n = if n = 0L then 1L else 1L + succ (n - 1L) ;;
<xavierbot>
^^
<xavierbot>
This expression has type int64 but is here used with type int
<Jeff_123>
jonafan: that's what i was trying to point out
<xavierbot>
xavierbot: fib 3 ;;
Jeff_123 has quit [Excess Flood]
<xavierbot>
^^^^^^^^^
<xavierbot>
Unbound value xavierbot
<context>
hha
<xavierbot>
Characters 10-11:
<bluestorm_>
let succ = let rec succ acc n = if n = Int64.zero then acc else succ (Int64.succ n) (Int64.pred n) in succ Int64.one;;
<xavierbot>
Parse error: illegal begin of top_phrase
<hcarty>
jcpiza: Please read the documentation, or ask, rather than flooding
<xavierbot>
val succ : int64 -> int64 = <fun>
Jeff_123 has joined #ocaml
<bluestorm_>
succ 10000L;;
<xavierbot>
- : int64 = 2L
<Jeff_123>
oops, sorry if i pasted somethign stupid
<bluestorm_>
:D
<Jeff_123>
I got booted
<bluestorm_>
let succ = let rec succ acc n = if n = Int64.zero then acc else succ (Int64.succ acc) (Int64.pred n) in succ Int64.one;;
<xavierbot>
val succ : int64 -> int64 = <fun>
<bluestorm_>
succ 10000L;;
<xavierbot>
- : int64 = 10001L
<bluestorm_>
succ 10000000L;;
<xavierbot>
- : int64 = 10000001L
<bluestorm_>
jcpiza: is that enough for succ ?
<Jeff_123>
wow, ocaml can add 1, that's amazing
<Jeff_123>
but can it add 2? Tell me bluestorm!
<context>
hahahaha
<bluestorm_>
:p
<Jeff_123>
hey context
<jcpiza>
yes, enough for succ, but not enough for fibo
<bluestorm_>
jcpiza: you may find some fibo benchmarks out there on the web
<Jeff_123>
remember "%i{somename}" ? I thought last night after my internet went out, why not just do "%{somename" like in tcl? The type system can work out the subtitution.
<jcpiza>
ok
<bluestorm_>
there was a "let's try a naive fibo in my pet language" fashion recently
<jcpiza>
i've got the conclusion of that ocaml can't run deeper recursive functions.
<bluestorm_>
jcpiza: no language can
<bluestorm_>
there is an OS limit
<jcpiza>
it's due to stack limitation established by ocaml.
<bluestorm_>
no it's not
<bluestorm_>
if you have intensive efficiency requirements, you'll use the native comiler
<Jeff_123>
jcpiza - go find me a turing machine and I'll show you an implementation of ocaml that can handle arbitrarily deep recursion.
<bluestorm_>
wich does not use any virtual machine
<Yoric[DT]>
I'd like to take that opportunity to troll against the big computer shootout :)
<Yoric[DT]>
s/computer/language/
<jcpiza>
recursive succ of 100'000 means at most 1'000'000 words in stack, but xavierbot was rebooted without reason to say me.
<bluestorm_>
xavierbot has added memory and time limitations
<bluestorm_>
because it's a bot
<Jeff_123>
xavierbot has artificial restrictions on its memory and cpu usage afaik
<bluestorm_>
the people running xavierbot don't want to turn it into a intensive computing farm for anybody who is in urgent need to compute fib 1000
<jcpiza>
how can i modify the stack limitation that did put ocaml? is there a user manual?
<Jeff_123>
the language shootout tells me that gcc compiled c is about 0% to 8% better than ocaml. Guess ocaml just sucks the big one. I'm with jcpiza.
<bluestorm_>
if you're using the native compiler, there is no stack limit set by ocaml
<bluestorm_>
(the only limit is the OS limit)
<Jeff_123>
Oh well. Have fun trying to teach the unteachable.
<jcpiza>
bluestorm_: i did put ulimit -s 524288 512 MiB for OS Stack! Ok? but ocaml crashes
<bluestorm_>
wich ocaml ?
<bluestorm_>
ocaml / ocamlc / ocamlopt ?
<jcpiza>
ocamlopt
desp has left #ocaml []
<bluestorm_>
then you're owerflowing the 512 MiB stack
<jcpiza>
stack_limit ;;
<xavierbot>
Characters 1-12:
<xavierbot>
stack_limit ;;
<xavierbot>
^^^^^^^^^^^
<xavierbot>
Unbound value stack_limit
<bluestorm_>
(or your stack isn't really i512 MiB)
<madroach>
Gc.get () ;;
<xavierbot>
Characters 1-7:
<xavierbot>
Gc.get () ;;
<xavierbot>
^^^^^^
<xavierbot>
Unbound value Gc.get
<jcpiza>
get().stack_limit ;;
<xavierbot>
Characters 1-4:
<xavierbot>
get().stack_limit ;;
<xavierbot>
^^^
<xavierbot>
Unbound value get
<mbishop>
Gc.stats();;
<xavierbot>
Characters 1-9:
<xavierbot>
Gc.stats();;
<xavierbot>
^^^^^^^^
<xavierbot>
Unbound value Gc.stats
<mbishop>
heh
<madroach>
jcpiza: do it that way: let conf = Gc.get ();; Gc.set {conf with stack_limit=1000000000};;
<xavierbot>
Characters 1-7:
<xavierbot>
jcpiza: do it that way: let conf = Gc.get ();; Gc.set {conf with stack_limit=1000000000};;
<xavierbot>
^^^^^^
<xavierbot>
Unbound value jcpiza
<xavierbot>
Characters 7-8:
<bluestorm_>
Gc module isn't available
<xavierbot>
Parse error: illegal begin of top_phrase
<bluestorm_>
module G = Gc;;
<xavierbot>
Characters 12-14:
<xavierbot>
module G = Gc;;
<xavierbot>
^^
<xavierbot>
Unbound module Gc
<hcarty>
I think Gc and Unix are two of the blocked modules on xavierbot
<Jeff_123>
probably just part of xavierbot's paranoia
<jcpiza>
let s = Gc.get().stack_limit ;; print s ;;
<xavierbot>
Characters 9-15:
<xavierbot>
let s = Gc.get().stack_limit ;; print s ;;
<xavierbot>
^^^^^^
<xavierbot>
Unbound value Gc.get
<hcarty>
I think rwnjones said this at some point in the past
<jcpiza>
much paranoia ehh?
<pango>
what about running code on your box instead of flooding the channel?
<hcarty>
jcpiza: Not really too much paranoia
<madroach>
jcpiza: try it at home, not with the bot.
<jcpiza>
i want to know the limit that did put this bot
<hcarty>
Then ask the author
<pango>
xavierbot runtime environment is not representative anyway
<jcpiza>
i don't touch the bot
<Jeff_123>
Jc, You're like a person trying to use a hammer to pound nails, but you insist on using the handle on the nail. Then you complain about how crappy the hammer is.
<Jeff_123>
Just hold it the right way and it'll work fine.
<pango>
iirc, it's easy to run into xavierbot memory limitations, even when not trying to
madroach has quit [Remote closed the connection]
<jcpiza>
Unix.environment();;
<xavierbot>
Characters 1-17:
<xavierbot>
Unix.environment();;
<xavierbot>
^^^^^^^^^^^^^^^^
<xavierbot>
Unbound value Unix.environment
<Jeff_123>
no you're not allowed to use the Unix module here
<jcpiza>
Sys.environment();;
<xavierbot>
Characters 1-16:
<xavierbot>
Sys.environment();;
<xavierbot>
^^^^^^^^^^^^^^^
<xavierbot>
Unbound value Sys.environment
seafood_ has quit []
<Jeff_123>
if anyone can complete this test in ocaml lemme know. I've tried but have been unable to come close to the minimum goal. http://www.spoj.pl/problems/VFMUL/
<Jeff_123>
there's another one with a less strict limit but I can't pass it either.
qwr has quit [calvino.freenode.net irc.freenode.net]
Hadaka has quit [calvino.freenode.net irc.freenode.net]
flux has quit [calvino.freenode.net irc.freenode.net]
qwr has joined #ocaml
flux has joined #ocaml
bluestorm_ has quit ["Konversation terminated!"]
Naked has joined #ocaml
Naked is now known as Hadaka
Yoric[DT] has quit ["Ex-Chat"]
Hadaka has quit [calvino.freenode.net irc.freenode.net]
Hadaka has joined #ocaml
opening` has quit [Connection timed out]
jsk has joined #ocaml
<jcpiza>
$ ulimit -s 524288 # 512 MiB for OS Stack.
<jcpiza>
$ ocaml
<jcpiza>
Objective Caml version 3.10.0
<jcpiza>
# let rec succ_rec n = if n = 0 then 1 else 1 + succ_rec (n - 1) ;;
<jcpiza>
val succ_rec : int -> int = <fun>
<jcpiza>
# succ_rec(67100000);;
<jcpiza>
Stack overflow during evaluation (looping recursion?).