<infoe>
wonder if the F# survival guide is more informative than F# wikibooks
tmaedaZ is now known as tmaeda0
caligula__ has quit [Read error: 104 (Connection reset by peer)]
caligula__ has joined #ocaml
jeddhaberstro has quit [Client Quit]
valross has joined #ocaml
caligula_ has joined #ocaml
caligula__ has quit [Read error: 60 (Operation timed out)]
valross has quit [Remote closed the connection]
valross has joined #ocaml
valross has quit [Remote closed the connection]
yakischloba has joined #ocaml
Alpounet has quit [Read error: 60 (Operation timed out)]
ulfdoz has joined #ocaml
joewilliams has quit [Remote closed the connection]
ttamttam has joined #ocaml
yakischloba has quit ["Leaving."]
ttamttam has quit ["Leaving."]
tmaeda0 is now known as tmaedaZ
Submarine has joined #ocaml
ski_ has quit ["Lost terminal"]
jonafan_ has joined #ocaml
ulfdoz has quit [Read error: 60 (Operation timed out)]
jorgenpt has joined #ocaml
<jorgenpt>
Given foo: a -> b, and bar: int -> b -> a, how can I get a function baz that consists of a foo (bar 1)? (so that the new function will pass it's type 'b' parameter as the second one to bar, and not to foo)
<jorgenpt>
If that makes sense. :-)
Yoric has joined #ocaml
<Asmadeus>
I can't find anything elegant, but you can always define 'let baz x = foo (bar 1 x)'
jonafan has quit [Read error: 110 (Connection timed out)]
<mrvn>
(fun b -> foo (bar 1 b))
Alpounet has joined #ocaml
pad has quit [Remote closed the connection]
<jorgenpt>
Oh neat, thanks mrvn
ttamttam has joined #ocaml
Yoric has quit []
_unK has joined #ocaml
Submarine has quit [Read error: 60 (Operation timed out)]
demitar has joined #ocaml
_zack has joined #ocaml
dmentre has joined #ocaml
ygrek has joined #ocaml
valross has joined #ocaml
rwmjones_lptp has quit ["Leaving"]
rwmjones_lptp has joined #ocaml
rwmjones_lptp is now known as rwmjones
_zack has quit ["Leaving."]
Yoric has joined #ocaml
Pimm has joined #ocaml
kaustuv has joined #ocaml
_unK has quit [Remote closed the connection]
valross has quit ["Ex-Chat"]
Submarine has joined #ocaml
maskd has joined #ocaml
_zack has joined #ocaml
<Gertm>
I'm starting with a little OCaml application to get the hang of the style. I want to make a list of all files in a directory, but I'm not quite sure how. I've got the Unix module to read the directory entries
<Gertm>
but I'm not sure how to make a list of this
<det>
What are you using to read the entries
<mrvn>
Gertm: you start with the empty list [] and then add one entry at a time with entry::old_entries
<det>
Sys.readdir will give you an array of entries
<det>
do you really need a list ?
<Gertm>
mrvn: yeah that's how I was going to go at it
<Gertm>
det: ah, an array will do fine, thanks
<mrvn>
But consider if you really need a list. Why not handle one entry at a time and then forget it again?
<Gertm>
mrvn: that would be a better approach yeah
<Gertm>
thanks, I'll need a bit of adjusting to this style of programming
avsm has joined #ocaml
<det>
It's a PITA to write a recursive loop to get all the entries because Ocaml uses an exception to indicate no more entries
<det>
So it is hard to be tail recursive
<mrvn>
try Some Unix.readdir ... with End_of_file -> None
<mrvn>
or similar
<det>
yes
<det>
you must convert to an option
<mrvn>
There should be some syntax to write a recursion that ends in an exception.
<Gertm>
yeahm that's what I was building
<Gertm>
is there an idiomatic way to do 'loop until exception' ?
<Gertm>
oh heh, same thing
<det>
You have to convert to an option
<Gertm>
okay
<mrvn>
let temp = try Some (...) with Exception -> None in match temp with Some x -> ... | None -> end of recursion
<det>
or use side effects
<det>
PITA
<det>
stblib should just return options
<det>
I understand it is done for performance reasons
<mrvn>
You can put that into a function though
<Gertm>
thanks guys
_zack has quit ["Leaving."]
<mrvn>
"Some" needs an extra allocation
<Yoric>
hi
<mrvn>
It is too bad options aren't encoded in memory as NULL for None and anything else for Some
<det>
that cant work
<mrvn>
Breaks 'a option option. :(
<mrvn>
i.e. Some None
<det>
breaks anything that needs full 32 bits
<mrvn>
det: why? They are always encoded as pointer to a block containing the 32bit
<Gertm>
you guys are making me want to stop learning ocaml :p
<det>
mrvn, Some 0 ?
<mrvn>
Gertm: ignore that. you don't need to know the internals how the compiler implements the details
<mrvn>
det: ints are tagges with 1
<mrvn>
tagged even
<det>
Yoric, Hi
<Yoric>
How do you do?
<det>
I am well
<det>
I just surprised myself about how easy it is to write a regular expression lexer from scratch
<det>
very little code to compile to NFA and search
<mrvn>
det: done that for writing a compiler
<det>
I am now tokenizing a python-esque syntax
<det>
with indent/dedent tokens
<det>
now I need to make the parser
<det>
ocamlyacc seems really attractive here, but I dont want to use any special tools for this
<det>
I am hoping I can make some combinators that can mirror the structure of ocamlyacc
<mrvn>
you wrote your own lexer. so keep going. :)
<det>
mrvn, what was your compiler for ?
<mrvn>
det: university course building one for a ocaml subset
<det>
my lexer looks very much like what a ocamllex source file would look like
<_andre>
and when i run "make install" it says "No rule to make target `all', needed by `libinstall'"
ksson has joined #ocaml
<gildor>
Leonidas: fill a bug, so that I can fix it when I'll have time and ask upstream (which is R. Jones from Red Hat) to release a new version with this patch ;-)
<Leonidas>
gildor: ok, will do
<Leonidas>
rwmjones: indeed, now I added the patch, rebuilt the package and installed it and lo and behold, it compiles without further changes.
<gildor>
_andre: the %: target is strange, normal way of doing thing is include $(OCAMLMAKEFILE)
<gildor>
_andre: trying something different is risky
<_andre>
gildor: well, i copied that from the docs in the "Handling subprojects" section
<gildor>
_andre: maybe outdated ?
<gildor>
rwmjones: do you plan to do a release of ocaml-bitstring with the patch that Leonidas point me to ?
<_andre>
gildor: if i do the include it says "No rule to make target `foo.cmi'"; it ignores the subproject settings
<gildor>
_andre: most of the time I put the makefile in the subproject dir and set/include OCAMLMAKEFILE
Pimm has joined #ocaml
ikaros has joined #ocaml
<kaustuv>
_andre: OCamlMakefile is a bit too magical. Is there a reason you can't use omake or ocamlbuild?
<_andre>
kaustuv: just that i still haven't learned to use either of those :p
<kaustuv>
_andre: I think learning omake is far easier than debugging OCamlMakefile, but ymmv
<gildor>
_andre: ocamlbuild is nice too, as much documented as OCamlMakefile ;-)
<_andre>
lol
<Leonidas>
omake is IMHO quite ugly, but the omake -P mode makes up for that :)
<Gertm>
Do I need to install something extra to get the Str module?
naufraghi has joined #ocaml
jimmyb2187 has left #ocaml []
<Gertm>
open Str;; -> regexp;; -> Error: Reference to undefined global `Str' what's missing?
<kaustuv>
Gertm: You just need to compile/link with str.cm(x)a
<Gertm>
but I'd like to use it in the toplevel to test something
<kaustuv>
#load "str.cma" ;;
<Gertm>
ok now it works.
<Gertm>
boy this gets confusing, are there good general rules to do this?
<kaustuv>
Make a .ocamlinit in the directory you run the toplevel from and add all the #load commands there.
ttamttam has joined #ocaml
<kaustuv>
This file is executed whenever the toplevel starts.
<Gertm>
thanks, I'll make that now.
jimmyb2187 has joined #ocaml
dmentre has left #ocaml []
Associat0r has quit []
<Gertm>
ah, the load makes sure the module is available and 'open' imports the functions in the current 'namespace'.. is that correct?
<kaustuv>
Yes. You'll need to #load anything that's not in the standard library documented in chapter 20 of the manual
<rwmjones>
gildor, yes, I do need to do that
<Leonidas>
good to hear that, so all distros will have working packages
<Leonidas>
hmm, I could create an Arch Linux package for that, actually..
<Camarade_Tux>
btw, I found OCamlMakefile pretty nice when linking against C and I'm using it when I'm not using ocamlbuild (now, if only I knew why I can't get a .cmxs with ocamlbuild: is it unsupported or am I doing something wrong?)
<gildor>
Camarade_Tux: mostly unsupported, but once someone write a rule for it, it should be ok
* rwmjones
had forgotten how much svn sucks compared to git
<orbitz>
i always forget how to use git
<thelema>
orbitz: practice more
<rwmjones>
git is horribly hard to learn, but once you become proficient, it is far better than anything else I've used
<thelema>
there's quite a bit more to keep track of mentally with git. All the pointers and such.
<Camarade_Tux>
gildor: ok, thanks, that's what I had inferred considering the error message I was getting
<Camarade_Tux>
I'll probably have to write a rule considering I'll probably use mfp's ld-ocaml ( :-) )
<Leonidas>
I could install extlib, but this seems to be a new dependency, right?
<Leonidas>
oh, it fails while compiling CIL
<Leonidas>
that was previously not the case.
<rwmjones>
hmm that wasn't good ... try 2.0.2 instead
lutter has quit ["Leaving."]
<rwmjones>
there's no new dependency needed
<rwmjones>
Leonidas, ^
<rwmjones>
gildor, ^^
<Leonidas>
rwmjones: that worked out of the box. Fine :)
* Leonidas
writes a followup to his debian bug report
<Pimm>
edo, go away
demitar has quit ["Ex-Chat"]
<det>
Conclusion: ocamlyacc is waayyyy nicer than parser combinators :-)
<flux>
det, tried menhir?
<det>
no
<det>
I was trying to avoid special tools
<flux>
it's backwards compatible. but better!
<det>
I wrote the lexer in pure code, and I am happy with that
<flux>
also iirc it has nice documentation as well
<det>
but parsing seems much less nice
<kaustuv>
you actually prefer ocamlyacc to a suitably selected collection of parser combinators?
<det>
yes
demitar has joined #ocaml
<det>
the combinator code is harder to glance at and understand
<det>
and I must eta expand all rules
<det>
and use lots of parens
<kaustuv>
Not sure what you mean by eta expand all rules, but since a general monadic combinator library implements full predictive parsing, you will generally observe that the combinatorized grammar follows exactly the natural grammar.
<det>
yes, it is the same structure
<det>
but awkward
<kaustuv>
With yacc, on the other hand, you have to fight with the LALR(1) restriction
<det>
and by eta expand I mean:
<det>
all rules need to be recursive
<det>
so I cant write simply:
Submarine has quit ["Leaving"]
<det>
let parse_foo_bar_baz = parse_foo >>> fun s0 -> parse_bar >> fun s1 -> parse_baz >>> fun s2 -> return (s0, s1, s2)
<det>
I have to write:
<det>
let parse_foo_bar_baz tokens = let p = parse_foo >>> fun s0 -> parse_bar >> fun s1 -> parse_baz >>> fun s2 -> return (s0, s1, s2) in p tokens
<det>
compare that to ocamlyacc:
<det>
foo_bar_baz: foo bar baz { $1, $2, $3 }
<det>
maybe that's not fair because I am using parse_ prefix
<det>
but even without:
<kaustuv>
if your parser type is: type 'a parser = token list -> 'a * token list, then you can do without it
<det>
let foo_bar_baz tokens = let p = foo >>> fun s0 -> bar >> fun s1 -> baz >>> fun s2 -> return (s0, s1, s2) in p tokens