<Asmadeus>
hmm, I think you have to name it? Trailing optional arguments are generally not great because it can't tell if you use "crypt str" if you want the partial function or if you want it used with default num
<def-lkb>
Also, replace <= by <, strings are 0-indexe so you don't never want to access str.[String.length str]
<n06rin>
def-lkb: man, are you so amazing.
<n06rin>
but how c -> c is work?
<n06rin>
why c?
<n06rin>
what is c in exch
<n06rin>
?
Neros has joined #ocaml
<def-lkb>
c is a variable (as opposed to 'a', 'b', 'c'… which are literal characters)
<def-lkb>
so it will match any value that has not yet been matched
<def-lkb>
you can interpret this case as "for all remaining characters", and the action is identity, that is "left them untouched".
<n06rin>
lol. I try to use you function. crept is return unit
<def-lkb>
yes, you choose to modify "str" inplace, you'll have to look at the content of str if you want to see the results
<n06rin>
oh, i see
<def-lkb>
try "let crypt' str = String.map exch str" if you want to get a new string
<n06rin>
ocaml is so hard to learn.
<def-lkb>
what are your previous experiences in programming?
<n06rin>
pascal. pure c, actionscript
<n06rin>
lua
<def-lkb>
ok, you never programmed in a typed language (--this may sound trollish, but types really has a different meaning in ocaml than in C or pascal--)
<def-lkb>
this is the main things that you will have to learn (in my opinion), once you get used to reading type signatures and using types as guide for designing your software, ocaml will feel easy and consistent :)
<n06rin>
i have trouble with sintaxing sugar likes a lot of function declaration and types.
derek_c has quit [Quit: leaving]
<def-lkb>
it's not syntax sugar. There is really few syntax sugaring in ocaml (labelled/optional arguments being an exception, as are some recent syntax for type variables, but they can largely be avoided when beginning)
<def-lkb>
I will advise you to avoid them at your point, and concentrate on core language.
<ggole>
That's debatable. let f x = x is sugar for let f = fun x -> x, for instance.
<def-lkb>
ggole: granted :).
<ggole>
It took me a little while to figure out fun vs function and some other things, too.
hto has quit [Quit: Lost terminal]
hto has joined #ocaml
mcsquiggedy has quit [Ping timeout: 256 seconds]
Neros has quit [Ping timeout: 256 seconds]
Neros has joined #ocaml
ben_zen has joined #ocaml
Arsenik has joined #ocaml
ollehar has joined #ocaml
breakds has joined #ocaml
Kakadu has joined #ocaml
derek_c has joined #ocaml
derek_c has quit [Client Quit]
derek_c has joined #ocaml
derek_c has quit [Client Quit]
derek_c has joined #ocaml
derek_c has quit [Client Quit]
derek_c has joined #ocaml
n06rin has quit [Quit: Leaving.]
ontologiae has joined #ocaml
void64 has quit [Quit: Leaving]
void64 has joined #ocaml
oriba has joined #ocaml
cyanure__ has joined #ocaml
derek_c has quit [Read error: No route to host]
derek_c has joined #ocaml
oriba_ has joined #ocaml
lusory has quit [Ping timeout: 245 seconds]
oriba has quit [Ping timeout: 264 seconds]
cyanure__ has quit [Remote host closed the connection]
Arsenik has quit [Remote host closed the connection]
Arsenik has joined #ocaml
Arsenik has quit [Remote host closed the connection]
ontologiae has quit [Quit: WeeChat 0.4.0]
lusory has joined #ocaml
ulfdoz has quit [Ping timeout: 268 seconds]
oriba_ is now known as oriba
eikke has joined #ocaml
mort___ has joined #ocaml
aspiri has joined #ocaml
<eikke>
fwiw: i toyed with 'composable folds' last night, i.e. have an API which allows to compose reified folds which can be calculated all in one pass over some list
<eikke>
e.g. allows to calculate the average of a list of ints in one pass, calculating both the sum & the list length in one pass
<ggole>
Can't you do that with List.fold_left using a tuple?
<eikke>
ggole: yes sure, and that +- what that code does, but in a more composable way
<eikke>
(imho)
<ggole>
Hmm.
<ggole>
Reminds me a bit of Common Lisp's loop.
<eikke>
I'm not familiar with CL
<ggole>
(loop for x in (list 1 2 3 2 1) summing x into sum counting x into count finally return (list sum count (/ sum count)))
<ggole>
All the functionality is built into the macro though.
<eikke>
so 'summing' and 'counting' are built-ins, no way to do other things?
<ggole>
Yep.
<ggole>
This looks much more modular
<ggole>
(This = your thing.)
<eikke>
that's the goal ;)
<ggole>
There's a bunch of the usual reductions like min, max
<eikke>
let f l = Fold.run (Tuples.pair <$> Fold.Operations.minimum <*> Fold.Operations.maximum) l would give you min & max in a go (well, 'a list -> ('a option * 'a option))
<ggole>
Right, so you've defined the obvious bits already
<ggole>
Nice idea.
<ggole>
I would tend to define a minmax from scratch though, since there is a comparison-avoiding trick.
<eikke>
agree
<eikke>
there's Fold.make ('acc -> 'a -> 'acc) 'acc : ('a, 'acc, 'acc) Fold.t which allows defining those yourself easily :)
<ggole>
Oh, interesting
<eikke>
most of the ones in Fold.Operations are defined like that, except for some which use explicit construction due to (I think) value restriction
<pippijn>
it has a lot of features and is not very modular
<pippijn>
I tried it, but not hard enough
void64 has joined #ocaml
g0d has quit [Quit: cya.]
othiym23 has quit [Ping timeout: 264 seconds]
othiym23 has joined #ocaml
ulfdoz has quit [Ping timeout: 246 seconds]
Snark has quit [Quit: leaving]
ggole has quit []
ulfdoz has joined #ocaml
luke_ has joined #ocaml
void64 has quit [Ping timeout: 264 seconds]
luke_ has quit [Read error: Operation timed out]
luke_ has joined #ocaml
mcsquiggedy has quit [Ping timeout: 256 seconds]
luke_ has quit [Quit: Leaving]
luke_ has joined #ocaml
skchrko has quit [Remote host closed the connection]
mcsquiggedy has joined #ocaml
<technomancy>
is ledit my best bet if I want civilised line input without rlwrap?
<technomancy>
I get "The dependency camlp5 of package ledit.2.03 is not available for your compiler or your OS." when trying to bring it in with opam
tani has joined #ocaml
<technomancy>
which seems to be bogus; the home page for camlp5 says "It is compatible with OCaml versions from 1.07 to 4.01.0."
Anarchos has joined #ocaml
<technomancy>
hm; maybe I shouldn't be on 4.01.0dev+trunk
milosn has joined #ocaml
tane has quit [Ping timeout: 240 seconds]
<Anarchos>
technomancy why ?
<technomancy>
Anarchos: just a guess; thinking camlp5 might be refusing to install because it's too new and it doesn't recognize the version
<technomancy>
it's not a very detailed error
<Anarchos>
technomancy just change the version number in the camlp5 source to accept the most recent one ?
<adrien>
iirc camlp5 has a whitelist of supported ocaml versions
<adrien>
which makes perfect sense
milosn_ has quit [Ping timeout: 264 seconds]
<technomancy>
adrien: it does make sense, but failing to show the list when your current version is not in it is pretty crappy
<technomancy>
"Sorry Mario, the Princess is in another compiler version."
<technomancy>
ooh nice; ledit's documentation consists of a 6-line readme
<adrien>
well, that's opam, not camlp5 :P
<technomancy>
this is going to be fun =\
<adrien>
hmm, are you sure?
<adrien>
there's nothing else?
<technomancy>
if there is more, it's well-hidden
chrisdotcode has joined #ocaml
tani is now known as tane
<Anarchos>
I still wonder how to control my ocaml program from C++ world
<technomancy>
I wonder if it would be better to FFI my way into readline proper
wmeyer has quit [Ping timeout: 245 seconds]
<technomancy>
since ledit doesn't honor .inputrc
testcocoon has quit [Quit: Coyote finally caught me]
<technomancy>
doesn't have a kill ring either =\
Arsenik has joined #ocaml
cyanure__ has joined #ocaml
<adrien>
I'm fairly sure I've seen all this in ledit
testcocoon has joined #ocaml
<Anarchos>
technomancy what is a killring ?
<technomancy>
Anarchos: every time you make a kill, it pushes an entry on the kill ring list
<technomancy>
C-y inserts the top entry, and M-y replaces the last insertion with the next entry on the ring
<technomancy>
I guess you'd call it clipboard history
<technomancy>
going through the FFI would probably make it a lot more difficult to customize tab completion though; which ledit seems to support from a cursory grep
Arsenik has quit [Remote host closed the connection]
cyanure__ has quit [Remote host closed the connection]
<technomancy>
oh, nope. it has a "complete_fn" field, but it's an integer, not a function. =\
<technomancy>
so much for that
wmeyer has joined #ocaml
<Anarchos>
Who did a main program in OCaml, with a GUI in another language ?
<pippijn>
I'd probably talk via pipes
<pippijn>
stdin/stdout
<Anarchos>
pippijn yes, so i need an infinite loop to deal with the commands arriving on the channels ?
<pippijn>
yes
Simn has quit [Quit: Leaving]
ulfdoz has quit [Ping timeout: 240 seconds]
<Anarchos>
pippijn but i don't know of an efficient way to define the syntax of the commands and their arguments
<pippijn>
why?
<pippijn>
what are you doing?
<Anarchos>
pippijn a math verifier
<pippijn>
oh
<pippijn>
you're the dypgen guy?
<Anarchos>
pippijn the guy using dypgen, yes :)
<pippijn>
how is that going?
<Anarchos>
i was able to parse ambigous propositional formulas perfectly :)
<pippijn>
I was thinking about dynamic parsers a little
<Anarchos>
i am not brave enough to try dynamic side of dypgen :)
<pippijn>
does dypgen allow you to add rules while parsing?
<pippijn>
if I someday take the time to learn how dypgen handles precedence parsing, I'll have my parser generator emit dypgen code
<pippijn>
it already emits menhir code for easy comparison
<pippijn>
without precedence, parsing C++ becomes super slow
<pippijn>
you get an exponential number of parses
<pippijn>
so comparison is impossible
<Anarchos>
pippijn you can add your own priority graph to dypgen
<Anarchos>
and assign the priority you want to each rule
<pippijn>
yeah, I saw that
<pippijn>
in the calc example
<wmeyer>
adrien: ping
<pippijn>
_install/bin/cpapa-bison wip/cc/ostream.i 0.12s user 0.00s system 95% cpu 0.130 total
<pippijn>
_install/bin/cpapa -trivial wip/cc/ostream.i 0.84s user 0.04s system 98% cpu 0.882 total
<pippijn>
=> bison is 8 times faster than my ocaml glr core
<Anarchos>
pippijn did you compile with ocamlopt and full optimizations options ?
<pippijn>
0.3 seconds without C compiler optimisation (gcc -O0)
<pippijn>
hm
<pippijn>
does ocamlopt remove if false () blocks?
<Anarchos>
no idea
<pippijn>
Anarchos: I didn't enable unsafe, and there are some asserts
<pippijn>
I'll kill the asserts
luke_ has quit [Remote host closed the connection]
<wmeyer>
pippijn: that's not too bad, how long does it take to parse boost headers
<pippijn>
wmeyer: haha
<pippijn>
I don't think I can parse boost headers, anymore
<pippijn>
C++11 :(
<wmeyer>
how about Qt
<pippijn>
well
<pippijn>
I don't think I can parse stdlib anymore, either
<pippijn>
even in c++98 mode, gnu uses c++11 stuff
<pippijn>
(meanies)
<pippijn>
who wants to help me define the grammar for c++11? :)
<wmeyer>
I see forest of hands !!!
<pippijn>
removing asserts: _install/bin/cpapa -trivial wip/cc/ostream.i 0.80s user 0.03s system 102% cpu 0.815 total
void64 has joined #ocaml
* wmeyer
shower time!
ollehar has quit [Ping timeout: 264 seconds]
chambart has joined #ocaml
ollehar has joined #ocaml
<pippijn>
oh
<pippijn>
well, ocamlopt isn't very good at optimising :)
<pippijn>
"hello";
<pippijn>
0.544 seconds now
<Anarchos>
pippijn ocamlopt should be renamed ocamlnative
<Anarchos>
cause it emits assembly code but not agressively optimized, though performances are decent
<pippijn>
it's ok
<pippijn>
it does inlining
<Anarchos>
yes but you have to ask for it explicitely
<pippijn>
oh?
<pippijn>
(9.569 seconds with bytecode)
<pippijn>
ok, so the ocaml engine is less than 50% of bison
<pippijn>
eh
<pippijn>
less than 50% away from it
<pippijn>
it's less than half as slow
<pippijn>
unoptimised C
<pippijn>
with optimised C, it's about 5 times slower
snearch has joined #ocaml
tane has quit [Quit: Verlassend]
<pippijn>
wmeyer: did you see my LALR(1) parser?
<pippijn>
wmeyer: it's faster than menhir ;)
<pippijn>
wmeyer: and I was thinking that maybe JITing it would be interesting
eikke has quit [Ping timeout: 245 seconds]
<pippijn>
I wonder if it's faster when using the operating system stack
<pippijn>
instead of an explicit stack and having it be tail recursive
<mrvn>
stack is stack. makes no difference. Alignment matters a lot though.
<pippijn>
mrvn: the explicit stack is a (ParseTables.state_id × SemanticValue.t) list)
<mrvn>
well, that isn't a stack
<pippijn>
it would be an interesting comparison
<pippijn>
immutable list vs. mutable array for stack
<mrvn>
doing it recursive would limit the amount you can parse
<pippijn>
ok, I don't want to write an array implementation now
<pippijn>
to do it efficiently, it should be a ring buffer
<pippijn>
ah no, not true
<Anarchos>
did you use ocamlprof to see where you really waste time ?
<pippijn>
Anarchos: lexing
<pippijn>
I checked with valgrind
<Anarchos>
for a recursive rule in ocamlyacc is it better to do S : A | S A or S : A | A S ?
<pippijn>
the former
<pippijn>
you build the list in reverse
<Anarchos>
S A ?
<pippijn>
yes
<Anarchos>
left recursive ?
<Anarchos>
anyway i just hav to parse less than 1000 occurrences of A so it don't really matters in fact :)
<Anarchos>
but i like to have efficient code ;)
chrisdotcode has quit [Remote host closed the connection]
<pippijn>
so, I made an array implementation
<pippijn>
same speed
pkrnj has joined #ocaml
<Anarchos>
and what standard module should i use if i need a map (key*value) over sorted keys, and i need to get the value and the next key for a key k1 ?
<pippijn>
List :\
<pippijn>
I don't think there is a module for that
<Anarchos>
sorted dictionnaries ?
<pippijn>
Map is sorted
<pippijn>
but I don't think it has a "next" function
<Anarchos>
ok i will use a list of pairs, and define my own comparison function to sort it
<Anarchos>
oh no wait
<Anarchos>
the result comes from an external unix process and i used " ... |sort" in it !
<pippijn>
:)
<Anarchos>
ok time to go to bed, i just stacked enough work for tomorrow
<pippijn>
good night
<Anarchos>
too long time i playd with ocamllex/ocamlyacc
<Anarchos>
i can't never remember those syntax :(
snearch has quit [Quit: Verlassend]
<pippijn>
oh, the array version is slower
<pippijn>
quite much slower
<pippijn>
1.6 vs 1.3 seconds
<pippijn>
the mutation costs
<Anarchos>
yes it may triggers the gc a lot more than a pure functional list i guess
<pippijn>
no
<pippijn>
why?
<pippijn>
the array is allocated once
<Anarchos>
modifiying mutable celles must trigger the minor_gc no ?
<pippijn>
it does?
<Anarchos>
no idea !
<pippijn>
I don't think so
<pippijn>
but it goes through caml_modify
<Anarchos>
which is the standard way to modify a cell in an array :)
<pippijn>
yes
<pippijn>
but I don't think there is a GC call involved
<Anarchos>
and if you change the size of the data in the cell, you must realloc space and so on
<pippijn>
but I don't do that
<pippijn>
it's an (int * 'a) array
<Anarchos>
ok so let valgrind set on the light :)
<pippijn>
no need
<pippijn>
it's slower than the list version
<pippijn>
so I killed the array version
<pippijn>
maybe having separate state/sval stacks would be faster
<pippijn>
that would be an int array and a 'a list
<technomancy>
trying to define a foreign function with Ctypes, I get «Exception: Dl.DL_error "/home/phil/.opam/4.01.0dev+trunk/lib/stublibs/dllctypes-foreign_stubs.so: undefined symbol: readline".»
<technomancy>
does that mean libreadline isn't installed in a way that ctypes can find it?
<pippijn>
0.9 seconds if I don't call user actions
<pippijn>
(and don't do anything with semantic values)
<pippijn>
so the stack is just an int list
<pippijn>
still slower than menhir's code backend (which is around 0.8 seconds)