<ker2x>
mmm, i'm still reading the manual and i have a question : how do i declare a function that take a single argument : a list of int ?
<ker2x>
let foo a int list = ... ? i don't think it's correct
<ker2x>
is it ?
<adrien>
nope
<adrien>
you don' t write the arguments type usually
<adrien>
let foo a = ...
<adrien>
if you want to do it, it's: let foo (a : int list) = ...
<ker2x>
yes, i know it work with just a
<ker2x>
haaaaa
<adrien>
but you shouldn't have to do it and you shouldn't do it most of the time
<ker2x>
let list_by_two (a: int list) = List.map (( * ) 2) a;;
<ker2x>
\o/
<ker2x>
probably not the most efficient :p
<ker2x>
dunno, just wanted to test :)
<ker2x>
thank you
djcoin has quit [Quit: WeeChat 0.3.9]
<ker2x>
and if i understand correctly, we can't to function overloading. so if i want to create the same function that accept float, i need to create another function with another name, right ?
<ker2x>
do*
<ker2x>
that use ( *. )
<Kakadu>
beginner42: also there is ocamlbrowser for looking to API
<Kakadu>
ker2x: yep
<ker2x>
aww. thx :)
djcoin has joined #ocaml
xavierm02 has joined #ocaml
beginner42 has quit [Remote host closed the connection]
fusillia_ has joined #ocaml
fusillia_ has quit [Remote host closed the connection]
fusillia has quit [Remote host closed the connection]
fusillia has joined #ocaml
ontologiae has quit [Read error: Connection reset by peer]
ontologiae has joined #ocaml
Progster has joined #ocaml
Yoric has joined #ocaml
Xizor has quit [Quit: So yes it's mIRC under wine under debian double peche capital. ;) I'll soon see in kfreeBSD.]
wtetzner has quit [Remote host closed the connection]
ChristianS has joined #ocaml
sivoais has joined #ocaml
Progster has quit [Ping timeout: 252 seconds]
chambart has joined #ocaml
mjonsson has joined #ocaml
aod has joined #ocaml
djcoin has quit [Quit: WeeChat 0.3.9]
djcoin has joined #ocaml
Vinnipeg has joined #ocaml
<flux>
kakadu, btw, have the qt bindings yet achieved the 'hello world' stage, or are there still some big problems unresolved?
<Kakadu>
flux: hello world was archived but there are big problems with covering full API. So big that most usable controls will be impossible to use. Btw, I have looked to QML and I think that is more modern way to make GUI. And it is not very good to make bad bindings to API wich will be deprecated soon.
<Kakadu>
I think that optimal way is to write QML GUI and put logic to OCaml
thelema_ has joined #ocaml
<flux>
I agree with that
<flux>
especially if it reduces the amound of bindings to create :)
<Kakadu>
maybe we can use some semi-automatical tool to make bindings from QML+C++ classes to OCaml
<flux>
I would be very surprised if existing tools would be up to the task
<adrien>
one of the most important things is that you have type-safety for signal and slots
thelema has quit [Ping timeout: 272 seconds]
<mcstar>
i asked on #qt once, if qml would make better binsings possible in general and for functional languages in particular
<mcstar>
bindings*
<mcstar>
maybe the right persons to answer this question werent around at that time...
<flux>
mcstar, so, no answer? or a negative?
<mcstar>
i can hardly remember it now, so could not have been to substantial an answer
<mcstar>
it is basically still c++
<mcstar>
qml can import modules
<Kakadu>
I thinks that a term `bindings for QML` should not be understanded as like as `bindings for QtGui`
<mcstar>
but those modules need to be written in c++
<mcstar>
so, there is a bridge to c++ from qml, you can write the logic in c++ and most of the gui in qml, but that doesnt mean you can interface with qml outside from c++
<Kakadu>
In QtGui we write bindings to QtGui classses when in QML we mostly should write our won classes (for example, for listmodes, other models, user objects, etc.). This our classes should call OCaml function where all buisness logic will be executed
<flux>
mcstar, well, I think it's a question of how big interface does C++ need to use to interact with the QML
<flux>
mcstar, if it's a small one, one can write a stub that routes ocaml calls into QML and vice versa
<flux>
if it's a big one, you need to generate metric shittons of binding code
<Kakadu>
It is not very bug
<mcstar>
idk, you are probably right
<Kakadu>
s/bug/big/ :)
Vinnipeg has quit [Quit: Leaving.]
<mcstar>
it would be nice to directly import ocaml code from qml
Vinnipeg has joined #ocaml
<mcstar>
the situation massively sucks, that there is no good binding for qt for functional languages
<mcstar>
but it is sort of understandable, since those frameworks are heavily oo
<mcstar>
there is f# with qyoto though
<Kakadu>
I also was written a generator, which reads methods, properties and signals to declare in C++ and generates C++ class which can be used in QML and which calls generated OCaml code
<mcstar>
f# has enough classic oo
<mcstar>
flux: im just not sure if it is possible or plausible to build the qyoto dlls on windows for example
<mcstar>
it works on linux though
<flux>
mcstar, well, how about python? not a functional language or not good bindings?
<mcstar>
python is not ocaml or haskell
<mcstar>
doesnt mean i wouldnt use it
<mcstar>
i fact i use it, just not much
<mcstar>
in*
<flux>
I was actually just asking if they have succeeded in the feat, and possibly why
<flux>
I guess python's accurate GC helps a bit, easier to deal with C++ perhaps with that
<mcstar>
i think the python qt binding is considered to be of high quality
<thizanne>
flux, mcstar : yes, the Qt bindings for python are really good
<thizanne>
but it's definitely not used as a functional language
ontologiae has quit [Ping timeout: 260 seconds]
<Kakadu>
There is a point of view that python is not a functional language. Because (I think) power of FP is type systems which forbids programmer to do stupid mistake. AFAIK python has dynamic weak type system
<flux>
well, I don't think type systems are the forte of FP only, I mean, isn't LISP a 'canonical' FP
<flux>
and CLISP doesn't even have TCO..
<mcstar>
why weak?
<companion_cube>
also, python has no real anonymous functions nor tail call optimization
<mcstar>
i dont think it is weak, just not statically typed
djcoin has quit [Quit: WeeChat 0.3.9]
<mcstar>
tco is an optimization, it doesnt define the language
<flux>
it does define the semantics in absense of infinite memory
<arsatiki>
Strong type system is what your language uses, weak ones are everything else.
<flux>
you cannot write a python program as a state machine that infinitely recurses into itself
<companion_cube>
mcstar: it does
<arsatiki>
(Last time I said that out loud it lead to two-hour holy war.)
<companion_cube>
it does define what can evaluate and what crashes
<flux>
well, you CAN, but it will eventually consume all memory and crash
<companion_cube>
also, python's closures are ugly
<mcstar>
if TCO is guaranteed, thats good
<mcstar>
but even if it isnt, your language can still be functional
<mcstar>
scheme and CL are equally functional
<companion_cube>
mcstar: no TCO implies a class of programs become buggy
<mcstar>
that doesnt matter
<f[x]>
wholy crap, is it friday already?
<mcstar>
you wouldnt write them that way, if TCO wasnt guaranteed
<flux>
and static typing implies certain class of non-buggy programs become illegal :)
<flux>
(..not sure where we are going..)
<mcstar>
nowhere
<mcstar>
lets put this effort into a good Qt binding
<thizanne>
<Kakadu> There is a point of view that python is not a functional language.
<thizanne>
in fact very few people use python as a functional language
<thizanne>
sometimes you write lambda instead of def, and sometimes you use list comprehensions, and that's all :)
<Kakadu>
:)
<arsatiki>
thizanne: I wouldn't categorize list comprehensions as a functional programming feature as such
<companion_cube>
if you don't have TCO, you need to write loops instead of recursion, and recursion is a defining point of functional languages ;)
<thizanne>
that's why you wouldn't categorize python as a functional language :)
<nicoo>
thizanne: Python is more dictionnal than functionnal ;)
<mcstar>
you can imagine a GC that collects the stack, and still wouldnt work 'in-place'
<mcstar>
not a typical tco
<mcstar>
or elimination
<nicoo>
Are there still (optimizing) compilers, in this age and day, that don't do TCO ?
<mcstar>
also, the first thing you really need to call a language functional, is to have full-featured lambdas, functions as values
<mcstar>
thats where python is disqualified as a functional language
ker2x has quit [Read error: Connection reset by peer]
<companion_cube>
also, yes
ker2x has joined #ocaml
<companion_cube>
(note that I mentioned lambdas too)
<mcstar>
also, clojure afaik doesnt have tco because of the jvm
<mcstar>
yet you would call it a dynamic lazy pure functional language
ontologiae has joined #ocaml
<companion_cube>
yes, it provides a workaround for tco
<companion_cube>
(which is not compiled as recursion, but looks like recursion to the programmer)
<companion_cube>
but that's a good point
<mcstar>
but the clojure compiler could check for TC condition and write a loop when possible i think
fraggle_laptop has joined #ocaml
<companion_cube>
no, there is a special construct in the language
<mcstar>
i know
<mcstar>
but that doesnt mean the clojure compiler couldnt do it automatically
<companion_cube>
yes
<mcstar>
the problem with that, is it would go unnoticed, when it couldnt do TCO, and people would run into problems
<mcstar>
but now, it wont accept the 'recur' or whatnot if it isnt in tail position
mcclurmc is now known as mcclurmc_away
<companion_cube>
it's like '@tailrec' in scala
<companion_cube>
for the very same problem
smondet has joined #ocaml
Vinnipeg has quit [Quit: Leaving.]
mcclurmc_away is now known as mcclurmc
Yoric has quit [Remote host closed the connection]
Yoric has joined #ocaml
Kakadu has quit [Quit: Konversation terminated!]
andreypopp has quit [Quit: sleep]
jamii has joined #ocaml
tac has joined #ocaml
<thelema_>
nicoo: yes, it's tricky to get C/C++ compilers (including gcc) to do tco
andreypopp has joined #ocaml
<companion_cube>
I thought gcc did it for -On when n >= 1 ?
<flux>
it probably does, but it's trickier when two functions recurse each other. although apparently the latest gcc has improvde that, as it broke delimcc..
<jonafan>
how does python not have fully featured lambdas or functions as values?
<tac>
jonafan: python has functions as values
<tac>
and it doesn't do lambdas because it helps enforce its coding standard (which is procedural)
<jonafan>
it's a lame solution, but the convention is to name an anonymous function _ when lambda syntax is not adequate
<mcstar>
def _(args):
<mcstar>
pass
<mcstar>
is not a value though
<mcstar>
maybe it is, but i dont think so
<jonafan>
_ is a value
<mcstar>
but the whole definition isnt
<mcstar>
like lambda x: expr
<mcstar>
you cant say:
<mcstar>
map(def _(x): return x+2, [1,2,3])
<jonafan>
so?
<mcstar>
so?
<jonafan>
i wouldn't argue that python is a functional language, but this seems very irrelevant to me
<mcstar>
well, it isnt irrelevant
<mcstar>
not the whole picture, but not irrelevant either
<tac>
jonafan: Python also doesn't have proper lexical scoping. (Or at least, you need to import variables to each inner scope with nonlocal).
<hcarty>
thelema_: Thanks for the patch!
<jonafan>
and iirc there wasn't a good solution to this until python 3
<jonafan>
which almost no one uses but admittedly probably has more users than ocaml
fusillia has quit [Quit: Leaving]
<thelema_>
hcarty: no problem. Now I can post something on the mailing list about how easy it is to install many versions of ocaml simultaneously
<hcarty>
thelema_: I won't argue
<hcarty>
thelema_: The -v option is very convenient. Before you could do the same thing but had to know the Subversion structure a bit: ocamlbrew -s release/4.00.1
<thelema_>
for a in 3.11.1 3.11.2 3.12.0; do ocamlbrew -o -v $a; done
<thelema_>
That's my use case - just installing a bunch of old ocaml versions
<hcarty>
It's something I wanted to have but never took the time to add. I'm glad you did.
Kakadu has joined #ocaml
<thelema_>
it took me *far* too long. despite the simplicity of the final patch, I found out way too much about bash.
hkBst has quit [Quit: Konversation terminated!]
<thelema_>
there are a lot of ways to not split a string on .s
<hcarty>
That's most if not all of the reason I had the hackish three environment variables in place.
hto has quit [Read error: Connection reset by peer]
hto has joined #ocaml
caligula__ has quit [Ping timeout: 246 seconds]
Cyanure has joined #ocaml
caligula__ has joined #ocaml
GnomeStoleMyBike has quit [Ping timeout: 264 seconds]
Yoric has quit [Ping timeout: 276 seconds]
mnabil has quit [Ping timeout: 246 seconds]
avsm has joined #ocaml
djcoin has quit [Quit: WeeChat 0.3.9]
andreypopp has quit [Quit: sleep]
Xizor has joined #ocaml
chambart has quit [Read error: Operation timed out]
tac_ has joined #ocaml
tac has quit [Ping timeout: 245 seconds]
andreypopp has joined #ocaml
sepp2k1 has joined #ocaml
Vinnipeg has quit [Quit: Leaving.]
sepp2k has quit [Ping timeout: 240 seconds]
arneis has joined #ocaml
metadave has joined #ocaml
tane has joined #ocaml
mcclurmc is now known as mcclurmc_away
Vinnipeg has joined #ocaml
Yoric has joined #ocaml
emmanuelux has joined #ocaml
emmanuelux has quit [Read error: Connection reset by peer]
<_habnabit>
i think if i could make just one change to ocaml, it would be to add sections
<thelema_>
_habnabit: sections?
<thelema_>
like array slices?
<_habnabit>
(x >=) instead of (<=) x
<thelema_>
oh. hmmm.
<_habnabit>
or (+ 3) or whatnot
<_habnabit>
haskell lets you bind either the lhs or rhs like this
<thelema_>
low on my list. type-directed print/compare is at the top of my list
<_habnabit>
I think I'm looking at a bug caused by reversing a comparison like this
<thelema_>
just write them out (fun x -> x >= y)
<_habnabit>
yeah, i guess
<_habnabit>
polymorphic print would be nice though
<thelema_>
we have polymorphic compare, and it's often useful, but it edges into buggy too often; not polymorphic print like this.
Vinnipeg1 has joined #ocaml
Vinnipeg has quit [Ping timeout: 256 seconds]
ben_zen is now known as BilboBaggins
BilboBaggins is now known as ben_Zen
ben_Zen is now known as ben_zen
CoverSlide has joined #ocaml
ontologiae has quit [Ping timeout: 264 seconds]
djcoin has joined #ocaml
<orbitz>
Hrm if I could change one thing about ocaml what would it be...
jbrown__ has joined #ocaml
|jbrown| has quit [Ping timeout: 276 seconds]
andreypopp has quit [Quit: sleep]
<xavierm02>
It might be because I'm not used to ocaml
<xavierm02>
But I really would like a return statement
<xavierm02>
because
<_habnabit>
xavierm02, batteries has that
<thelema_>
both batteries and core have modules that provide something like.
<xavierm02>
ah
<xavierm02>
but the "normal" ocaml doesn't?
<thelema_>
no
<xavierm02>
:(
<thelema_>
if you're programming without this library, use an exception to return
<thelema_>
ocaml exceptions are quite cheap
<xavierm02>
hm
<xavierm02>
that could work
<xavierm02>
but feels a bit weird
<xavierm02>
I'll try it
<xavierm02>
thank you for the tip :)
<thelema_>
exceptions in ocaml are much more common than objects
<adrien>
xavierm02: first, split your functions more: that will alleviate the need for "return" a _lot_
<adrien>
xavierm02: my other point is that you need to return something
<adrien>
"return -1" and "return NULL" for errors are not proper ocaml
<adrien>
the proper way for such things is exceptions
<adrien>
or option types
<tac_>
xavierm02: "return" as in "return x + 1"?
Vinnipeg1 has quit [Quit: Leaving.]
<tac_>
ah... I guess since Ocaml has imperative definitions, that even makes sense
<adrien>
but you need to have something meaningul to return unlike typical C where you would put garbage
<thelema_>
tac_: I wouldn't say it makes sense, the definitions can't be nested in anything.
<tac_>
thelema_: well, it makes a lot more sense than it might in haskell :)
<thelema_>
you can declare types inside functions in haskell?
<xavierm02>
let me give you an example
<xavierm02>
I have a number N
<xavierm02>
a a list L
<xavierm02>
containing m numbers
<xavierm02>
and i want to check if one of the numbers in L divides N
<thelema_>
List.mem n l?
<xavierm02>
I know how to stop searching
<xavierm02>
when i find the first one
<xavierm02>
in the recursive version
<thelema_>
List.find (fun x -> n mod x = 0) l
<xavierm02>
but not in the iterative
<xavierm02>
that's cheating
<xavierm02>
-.-
<thelema_>
:)
<xavierm02>
I mean
<xavierm02>
my example
<xavierm02>
is just an example
<xavierm02>
it's not that simple
<xavierm02>
in fact
<thelema_>
ok, you want to do this iteratively...
<xavierm02>
I don't even have all the data in memory at once
<xavierm02>
so I really can't do that
<xavierm02>
yeah
<xavierm02>
making a recursive function for something like thjis for me
<xavierm02>
is
<xavierm02>
overkill
<xavierm02>
and
<_habnabit>
'overkill'?
<xavierm02>
"less obvious"
<xavierm02>
when i read it
<xavierm02>
yeah
<xavierm02>
some problems
<_habnabit>
that's the first time i've seen that definition of overkill
<xavierm02>
need recursion
<xavierm02>
to be expressed easeally
<xavierm02>
that one
<thelema_>
try let i = ref 0 in while i < m do if n mod (get i) = 0 then raise Found i; done; -1 with Found i -> i
<xavierm02>
is easier to express iteratively
<_habnabit>
xavierm02, just so you know, you can put more than 1-4 words on a line in IRC
<xavierm02>
^.^
Vinnipeg has joined #ocaml
<xavierm02>
hm
<thelema_>
also: exception Found of int
Cyanure has quit [Remote host closed the connection]
<xavierm02>
what is the -1 for?
<thelema_>
xavierm02: but even with 'return', the "overhead" of writing and using the higher order function is not an issue
<xavierm02>
well
<xavierm02>
from what i know it depends
<thelema_>
the -1 is the return value when no index matches
<xavierm02>
if you manage to get tail recusion or not
<xavierm02>
and if you don't, your start wasting a lot of memory...
<thelema_>
tail recursion is generally easy, and has to be done once, no matter how many searches you want to do.
<xavierm02>
so
<xavierm02>
-1 is what is returned
<xavierm02>
if no exception is raised
<xavierm02>
and if an exception is raised
<thelema_>
yes, bad style; I should have written `done; None with Found i -> Some i`
<xavierm02>
it returns (i -> i)( n )
<xavierm02>
?
Vinnipeg has quit [Client Quit]
<thelema_>
(i -> i) n? no, it just returns i
<xavierm02>
yeah
<xavierm02>
but
<xavierm02>
the function you specify
<xavierm02>
is used to transform the exception
<xavierm02>
into a result of the same type as -1
<xavierm02>
right?
<xavierm02>
which in this case
<thelema_>
something like that, yes.
<xavierm02>
means simply returning it
<thelema_>
it's actually pattern matching on all known exceptions.
<xavierm02>
what did you say about "bad style"?
<xavierm02>
I didn't get what you wanted to change
<thelema_>
returning -1 is bad style.
<xavierm02>
oh
<thelema_>
It's better to return None when the item is not found
<xavierm02>
but can you do that?
<thelema_>
or even raise an exception - Not_found is used in the stdlib for this
<xavierm02>
because
<xavierm02>
None
<thelema_>
try let i = ref 0 in while i < m do if n mod (get i) = 0 then raise Found i; done; None with Found i -> Some i
<xavierm02>
won't be the same type as the indexes
<xavierm02>
ah
<xavierm02>
Some is the same type as None I guess
<thelema_>
type 'a option = Some of 'a | None
Xizor has quit [Remote host closed the connection]
chambart has joined #ocaml
Submarine has joined #ocaml
mcclurmc_away is now known as mcclurmc
tane has quit [Quit: Verlassend]
djcoin has quit [Ping timeout: 244 seconds]
<nicoo>
thelema_: while !i < m
<thelema_>
nicoo: ah, yes.
<nicoo>
Np
smerz has joined #ocaml
<thelema_>
anyone up for some ocaml micro-optimization? I want to get rid of (or better understand) the hot instruction here: http://pastebin.com/05y7ezQP
<mfp>
thelema_: how trustworthy are the costs reported there? (and btw what are you using to get this?) it's a bit strange to have 0.00 : 476fe8: callq 478e60 <camlD2fa__next_q_9246> yet that load from (%rsp) taking 70.13
<thelema_>
mfp: I'm using the linux `perf` tool to get these numbers
<thelema_>
'perf record <program> <args>' then 'perf report'. It should be using CPU counters to get these numbers with basically no overhead
chambart has joined #ocaml
<mfp>
sounds great
<thelema_>
mfp: I'm thinking that the load is the String.unsafe_get... In which case there's not much I can do about it.
<thelema_>
and I think the 70% is not 70% total program runtime
<mfp>
oh, isn't it just the (i + 1)
<mfp>
with i being preserved in the stack?
<thelema_>
because d2sm_loop only accounts for 19.53% of total runtime
answer_42 has quit [Quit: WeeChat 0.3.9]
Yoric has quit [Ping timeout: 272 seconds]
<_habnabit>
profile it with cachegrind
<thelema_>
I see the add on the next line, which is related, but it seems to happen after the mov rsp
<thelema_>
_habnabit: can you help me interpret the cachegrind results?
<_habnabit>
sure!
<_habnabit>
see also: kcachegrind/qcachegrind
<thelema_>
anything other than --tool=cachegrind that I need to do when profiling?
<_habnabit>
I don't think so
<_habnabit>
unfortunately my zsh history got truncated and I can't find it
<mfp>
thelema_: AFAICS %rsi is i; it is being saved into the stack before the call to next_q, then recovered and incremented
<thelema_>
oops, had compiled w/o debug for perf; re-running valgrind with debug compilation
<thelema_>
btw, I just checked in a fix to its lookup that makes a 3x difference in this code.
ontologiae has joined #ocaml
<thelema_>
I think I really want DIET for this application; the domain of each tree is character, and there's a *lot* of adjacent identical values in the range
<thelema_>
also, these trees are specialized for ints.
<thelema_>
thus the *I*
Submarine has quit [Quit: Leaving]
xavierm02 has quit [Quit: Leaving]
rwmjones has quit [Read error: Operation timed out]
avsm has joined #ocaml
Neros has joined #ocaml
chambart has quit [Ping timeout: 246 seconds]
smondet has quit [Quit: ERC Version 5.3 (IRC client for Emacs)]
rwmjones has joined #ocaml
GnomeStoleMyBike has joined #ocaml
tac_ has quit [Ping timeout: 245 seconds]
ontologiae has quit [Ping timeout: 245 seconds]
Kakadu has quit [Quit: Konversation terminated!]
Yoric has joined #ocaml
sivoais is now known as cooljj_21
sepp2k1 has quit [Remote host closed the connection]
cooljj_21 is now known as sivoais
jamii has quit [Ping timeout: 272 seconds]
BiDOrD_ has quit [Read error: Operation timed out]
BiDOrD has joined #ocaml
tufisi has quit [Ping timeout: 256 seconds]
GnomeStoleMyBike has quit [Ping timeout: 264 seconds]