gildor changed the topic of #ocaml to: Discussions about the OCaml programming language | http://caml.inria.fr/ | OCaml 3.12.1 http://bit.ly/nNVIVH
wutwatwhat has joined #ocaml
wutwatwhat has quit [Ping timeout: 276 seconds]
ulfdoz has quit [Ping timeout: 240 seconds]
ulfdoz has joined #ocaml
oriba_ has joined #ocaml
oriba has quit [Ping timeout: 248 seconds]
oriba_ has quit [Quit: oriba_]
mjonsson has joined #ocaml
Tobu has quit [Ping timeout: 272 seconds]
Tobu has joined #ocaml
avsm has quit [Quit: Leaving.]
emmanuelux has quit [Ping timeout: 264 seconds]
mnabil has joined #ocaml
mjonsson has quit [Remote host closed the connection]
JoeyA has joined #ocaml
<JoeyA> What's a good resource for learning OCaml for someone familiar with Haskell?
larhat has joined #ocaml
larhat has quit [Read error: Operation timed out]
glguy has joined #ocaml
ygrek has joined #ocaml
JoeyA has quit [Quit: Leaving]
andreypopp has joined #ocaml
larhat has joined #ocaml
Tobu has quit [Ping timeout: 260 seconds]
sivoais has quit [Ping timeout: 260 seconds]
glguy has quit [Quit: Quitting]
Tobu has joined #ocaml
eni has joined #ocaml
cdidd has joined #ocaml
eni has quit [Ping timeout: 276 seconds]
Cyanure has joined #ocaml
sivoais has joined #ocaml
Xizor has joined #ocaml
Cyanure has quit [Ping timeout: 264 seconds]
jathd has joined #ocaml
eni has joined #ocaml
Zedrikov has joined #ocaml
my_nick_was_take has joined #ocaml
Zedrikov is now known as counter
my_nick_was_take is now known as Zedrikov
andreypopp has quit [Quit: Quit]
ulfdoz has quit [Quit: brb]
avsm has joined #ocaml
larhat has quit [Read error: Connection reset by peer]
larhat has joined #ocaml
ulfdoz has joined #ocaml
counter is now known as countdown
eni has quit [Ping timeout: 276 seconds]
tetsuya_ has joined #ocaml
<tetsuya_> hi all
<pippijn> hi tetsuya_
<tetsuya_> i don't understand why the following line it's wrong:
<tetsuya_> let a = "b" in Printf.printf a;;
<tetsuya_> instead the simple:
<tetsuya_> Printf.printf "b";;
<tetsuya_> it's right
<tetsuya_> someone can help me to understand why?
<tetsuya_> thanks in advance for any help
<tetsuya_> the following line it's wrong too, but i don't understand why:
<tetsuya_> Printf.printf ("a" ^ "b");;
<tetsuya_> it think must be equal to
<tetsuya_> Printf.printf "ab";;
<tetsuya_> but it's not equal
<tetsuya_> My question it's hard to understand? Or it's just a too boring question?
<Qrntz> it's hard (for me, at least) to answer without digging into the internals of Printf
<Qrntz> basically, format strings are somewhat different from regular strings, even though they use the same syntax
ygrek has quit [Ping timeout: 276 seconds]
<tetsuya_> thanks
<Qrntz> sorry, I just don't have enough knowledge of the internals to explain that fully
<Qrntz> but basically, your format string should be string constants
<Qrntz> in C, using a «char *» variable as a format string works, but will warn you about the impossibility of type-checking the format
<Qrntz> in this example in ocaml, it doesn't, but as I already said, I'm not competent enough to explain why
<tetsuya_> thanks, at least it's not a language specific issue, but just a printf special case
<Qrntz> that's correct; printf in ocaml employs quite a lot of Obj.magic
ygrek has joined #ocaml
robthebob has joined #ocaml
<pippijn> tetsuya_: printf is also a lot of compiler magic
robthebob has quit [Client Quit]
<tetsuya_> thanks for the explanation
<pippijn> tetsuya_: without magic, you would have to wrap every argument in an ADT
thelema_ has joined #ocaml
tetsuya_ has quit [Ping timeout: 265 seconds]
foocraft_ has joined #ocaml
vext01_ has joined #ocaml
<vext01_> is it possible to pattern match upon types?
<vext01_> match x with int -> ... | bool -> ...;;
<vext01_> for example
rwmjones has quit [*.net *.split]
comak has quit [*.net *.split]
tufisi has quit [*.net *.split]
thelema has quit [*.net *.split]
ski has quit [*.net *.split]
foocraft has quit [*.net *.split]
tufisi has joined #ocaml
<pippijn> vext01_: no, you need to wrap things into Int, Bool, ...
<vext01_> i see
<vext01_> is this like boxing in java?
<Qrntz> you could pattern match using gc tags, but this is to a certain degree unsafe and not really a good practice
<pippijn> not really
<vext01_> perhaps my approach is wrong
rwmjones has joined #ocaml
<vext01_> im writinga function that takes a variable and based on type generates a printf format string
ski has joined #ocaml
<vext01_> how would you achieve this?
<tomprince> What are you oging to use that function to do?
rwmjones has quit [Ping timeout: 265 seconds]
<vext01_> tomprince: well the format string will be passed to printf ultimately
<vext01_> (i have been using ocaml for about 2 days, so i could be insane)
rwmjones has joined #ocaml
rwmjones has quit [*.net *.split]
ski has quit [*.net *.split]
<tomprince> Well, I think printf format strings need to contant. But in any case, what are you trying to do that you are asking about writting printf format strings dependent on a type?
<tomprince> You asked for X, but really want to do Y. I don't think X is possible, but I bet Y is.
<vext01_> i dont understand your question
<Qrntz> printf format strings indeed need to be constants
Tianon has quit [Ping timeout: 260 seconds]
<Qrntz> the discussion a bit earlier was just about that
<adrien> they're type-checked
<vext01_> ok, ill find another way
Tianon has joined #ocaml
Tianon has quit [Changing host]
Tianon has joined #ocaml
<pippijn> what are you actually trying to do?
<vext01_> its nothing amazing, just printing items in a list which could hold any type
<pippijn> what's the type of that list?
<vext01_> anything
<pippijn> "anything list"?
<vext01_> i suppose that's "a' list"
<Qrntz> «'a list»
<Qrntz> I am fairly sure that won't be possible with ocaml's type system, though
<vext01_> hrm
<pippijn> you can't put both int and string in 'a list
<pippijn> because once you put an int in a 'a list, 'a turns into int
<tomprince> Well, it is probably best to write something like 'a list -> ('a -> unit) -> unit
<tomprince> Where the second argument is the print function to use.
<pippijn> and still, 'a will be concrete
<vext01_> i see
<adrien> you can't give either "int list" or "float list" to the same function anyway (not if the function does anything which depends on the items in the list and not merely on the structure of the list)
<vext01_> is there a function which converts any type to a string?
rwmjones has joined #ocaml
ski has joined #ocaml
<Qrntz> no, there are specific coercions though
<vext01_> i guess this is also quite dymnamic and not in the spirit of ocaml
<adrien> (sp "%f\n", [1.;2.;3.]) would work however
<Qrntz> e. g. string_of_int
<pippijn> ah, now I know where you are going
<pippijn> toString
comak has joined #ocaml
<vext01_> or str() in python
<adrien> vext01_: what you can do is have both the printer and the list in the same structure
<vext01_> etc
<pippijn> vext01_: no, but you can achieve stringification with syntax extensions (like deriving (Show))
<vext01_> deriving?
<pippijn> google ocaml deriving
<vext01_> ok, cheers for your help
<tomprince> vext01_: It may also be that you never really need something like that, after you have gotten used to ocaml.
<pippijn> you may also like the ocaml debugger to print values
<pippijn> or sexplib (I use that for printing values a lot)
<vext01_> yeh, im just new, i'll pick it up
<vext01_> probably trying to apply the wrong idioms etc
<mrvn> What else do you want to do with the list? Because if you only want to print it then put closures into the list
<vext01_> i have not got that far
<vext01_> tbh these programs are just experiments
<vext01_> i dont really have a end goal for any of the experiments other than to learn about ocaml
<mrvn> In the next ocaml release you can use GADTs to generate your format strings and create an universal list of value + format. But till then that is rather complex.
<mrvn> If you just want a few different things in the list then use type t = Int of int | Float of float | Str of string let print = function Int i -> print_int i | Float f -> print_float f | Str s -> print_string s
eni has joined #ocaml
<vext01_> mrvn: that is polymorphism?
<mrvn> no, that is simply a variant type.
<vext01_> i see
eni is now known as albacker
albacker has quit [Changing host]
albacker has joined #ocaml
emmanuelux has joined #ocaml
<pippijn> vext01_: what language do you come from?
<albacker> do you store modules in .ml?
<thelema_> albacker: yes
cdidd has quit [Ping timeout: 245 seconds]
<vext01_> pippijn: i write a lot of C and a bit of python
<vext01_> i know java, but generally dont use it much
vext01_ has quit [Remote host closed the connection]
vext01 has joined #ocaml
cdidd has joined #ocaml
<thelema_> vext01: OCaml will be more like C in terms of printing; no universal "to string" function is built-in.
ygrek has quit [Quit: Leaving]
<pippijn> sometimes I wish for that kind of introspection
<pippijn> in java, I can use reflection to dump all fields of objects recursively
|Lupin| has joined #ocaml
<|Lupin|> Hello
<thelema_> pippijn: part of ocaml's design is that type information is not present at runtime. If you want this, you can use G'caml http://web.yl.is.s.u-tokyo.ac.jp/~furuse/gcaml/
<pippijn> thelema_: right
<pippijn> I like that design decision
<thelema_> The down side is that types become much more complex.
<thelema_> val plus : [| int -> int -> int | float -> float -> float |] = <generic>
<pippijn> if type information is present at runtime, people tend to use it and create hard to understand code
<|Lupin|> I've a batteries related question... Is there a way to use regular expressions to match in ropes ?
<thelema_> |Lupin|: at the moment there's no regexp engine that will match in ropes.
<thelema_> |Lupin|: It's been on my todo list for a long time, but never has come to the top
<|Lupin|> thelema_: okay. And is there another structurethat would provide unicode strings and support regexp matching ?
<thelema_> UTF8
<|Lupin|> thelema_: hmm...
<thelema_> although you'd have to use pcre to match on it
<thelema_> or the regexp matcher from camomile
<|Lupin|> okay
<|Lupin|> the thing is
<|Lupin|> I need to know the size of a string not in bytes but in characters, so I assume that if I use an UTF8-encoded representation that information won't be available, or am I wrong ?
<thelema_> why wouldn't UTF8 strings be able to have character length?
<|Lupin|> thelema_: so are there three regexp matchers around ? A binding for PCRE,one in Camomile andone in Batteries ?
<thelema_> batteries doesn't have its own regex matcher. Just two regexp matchers that I know that handle unicode
<|Lupin|> thelema_: don't know, just an assumption of mine. Which function would you use to know the length of a UTF8 string ?
<|Lupin|> thelema_: batteries uses the one of Camomile ?
<thelema_> BatUTF8.length
<|Lupin|> ahah, didn't have a look to that one, thanks.
<thelema_> batteries doesn't export any unicode regexp engine.
<thelema_> its unicode internals (except for BatRope) are almost identical to camomile's
<|Lupin|> thelema_: Where is BatUTF8, ls ? Just cloned the git repo of batteries and used rgrep -l BatUTF8, didn't show any module...
<|Lupin|> (btw: the intendeduse of regexps is to split strings into words, but perhaps there is a more adequate tool in batteries to perform just this task?)
<pippijn> batUTF8.ml
<|Lupin|> I don't have this file...
<|Lupin|> just tried a find and no result at all in the whole batteries-included git tree.
<thelema_> |Lupin|: batutf8 is the old name in 1.x
<pippijn> what is it called, now?
<thelema_> in the git tree, it's Ulib.UTF8, I think
<thelema_> one sec
<thelema_> yes, Ulib.UTF8
<thelema_> the source for this is in libs/ulib.ml*
* |Lupin| removed the old 1.x version because batStr exported only search, not split.
<thelema_> wait, you just want to split your string into words?
<thelema_> and you think you need regexps for this?
<thelema_> what delimiter do you want between words?
<|Lupin|> thelema_: well, jst looking for asolution that does not require too much code...
albacker has quit [Read error: No route to host]
<|Lupin|> thelema_: any sequence of one or moreblanks
<|Lupin|> spaes, tabs, linefeeds, carriage return...
<thelema_> hmm... Batteries doesn't have a nsplit that works on multiple splitting strings at once...
<|Lupin|> thelema_: yes, that's what I figured out,too. So,you see, I can't think of another way than regexps...
<|Lupin|> thelema_: for instance, in Haskell there is a "words" function. I wanted to write an equivalent...
<thelema_> since all the things you want to split on are single characters, I'm sure that a versino of nsplit that uses a predicate instead of substring search wouldn't be difficult to add to batteries
<|Lupin|> thelema_: no not only single characters... AsI said sequences of blanks should be considered as delimiters, too.
<thelema_> sure, but that's just dropping empty words
<|Lupin|> okay...
<|Lupin|> I like the Ulib.UTF8 strings... How do I access thismoudle ? open Batteries.Ulib.UTF8 ?
<thelema_> no, just Ulib.UTF8
<thelema_> Ulib.Text is re-exported as Batteries.Text (replaces BatRope)
<thelema_> I recommend trying to stick with the text module; if there's something from Ulib.UTF8 that you want, I can provide it in Text
<|Lupin|> thelema_: ah okay, thanks.
<|Lupin|> thelema_: okay, thanks. So how would you implement words on top of Text ?
<thelema_> by iterating through the characters in reverse order, identifying the split characters' offsets and then doing appropriate slices
jathd has quit [Quit: ERC Version 5.3 (IRC client for Emacs)]
eni has joined #ocaml
<thelema_> |Lupin|: https://gist.github.com/2393587 <- nsplitp for string
tetsuya_ has joined #ocaml
emmanuelux has quit [Read error: Connection reset by peer]
snearch has joined #ocaml
jathd has joined #ocaml
<eni> Error: This expression has type terme but an expression was expected of type
<eni> terme
<eni> what does this mean?
<adrien> ocaml 3.11?
<adrien> and in the toplevel?
<eni> yes
<eni> toplevel
<eni> and yes 3.11
<jathd> eni: would you happen to have redefined the type "terme"?
<eni> yes
<eni> but i re-run the definition (tuareg)
<adrien> and a function is refering to the older definition of terme
<eni> re-evaluated
<jathd> well apparently you forgot to redefine something
<eni> it's ok, i closed emacs, and reopened it, it works.
<eni> thanks
<jathd> Yeah, sometimes there's nothing like starting with a blank slate again
mononofu has joined #ocaml
snearch has quit [Quit: Verlassend]
mononofu has quit [Ping timeout: 276 seconds]
<mrvn> thelema_: I wonder if one can use GADTs for your "plus" function without it becoming runtime type information.
<|Lupin|> thelema_: thank you
<|Lupin|> thelema_: why would you iterae over the characters in reverse order rather than from left to right ?
Tobu has quit [Ping timeout: 272 seconds]
<|Lupin|> thelema_: regarding nsplit: I think it would not work well on UTF8 strings. Assume your delimiter is a character whose UTF8 encoding is multibyte. Then nsplitp won't be usable, or am Imissing something ?
Tobu has joined #ocaml
<thelema_> mrvn: yes, using String.nsplitp on a string containing multibyte characters would fail
<thelema_> That nsplitp is just for strings. Here's the version (not tested) for Ulib.Text (ropes)
<|Lupin|> thelema_: oh cool, thanks !
<thelema_> mrvn: I don't think so; at least not without another parameter indicating what type the incoming values were
<thelema_> which is the tag, just separate
<|Lupin|> thelema_: btw, I had found a module defining unicode character categories in batteries 1.4. Can't find it the git tree... Would you please accept to tell me where it is ?
<|Lupin|> thelema_: to which branch is it that you push these commits ?
<|Lupin|> they don't seem to be in master... ?
eni has quit [Ping timeout: 276 seconds]
<thelema_> not pushed yet
<thelema_> I'm trying to get quicktests to work in ulib
<thelema_> also, the character classes iirc, have been dropped. The idea behind this was probably that if you needed really complex unicode handling, you'd use chamomile
<thelema_> and that batteries would only cover the most common cases
<hcarty> thelema_: Any chance that ulib can still become BatUlib before 2.0 is released?
<thelema_> hcarty: yes, although I'm thinking about something a bit more complex - have BatText parent all the unicode code and expose utf8 ropes.
<thelema_> |Lupin|: I just pushed my code to github as thelema/nsplitp. Please test
<vext01> when you install an ocaml library (that uses findlib) do you have to has some database or something after?
<vext01> i have installed ocaml-glpk
<vext01> its shows up in `ocamlfind list`
<thelema_> vext01: ocamlfind uses the filesystem as its database; scanning directories and reading the META files in them to identify what's installed
<vext01> but i am unable to "open Glpk" unless i am in the same dir as the library (/usr/local/lib/ocaml/site-lib/glpk)
<vext01> thelema_: the package seems to have installed the META file
<thelema_> vext01: in the toplevel, do `#use "topfind";;` and then `#require "gplk";;`
<thelema_> the first adda ocamlfind magic to your toplevel, the second loads everything needed for gplk
<vext01> thelema_: ok that seems to have worked
<vext01> so why the multiple module loading interfaces?
<vext01> the module docs didn't describe this step
<thelema_> vext01: because ocaml itself comes with a really crappy one, ocamlfind is the community improvement on this.
<vext01> just "open Glpk;;" with a uppercase G.
<vext01> eesh
<thelema_> ocaml itself has a lot of 1980's assumptions on library management
<hcarty> vext01: open does something different than #load or #require
<vext01> thelema_: the end goal is to package this up for use with a package manager, so surely i should use the "official" way, despite how crappy it is?
<Qrntz> the official way is de facto findlib now
<thelema_> yes, the ocaml community is *finally* moving to findlib for package management.
<vext01> it worries me that the docs for the package say to do something else
<Qrntz> I don't really know a single library that doesn't use findlib for installing itself
<hcarty> thelema_: To be fair, it's been that way for a while in Debian, Fedora, GODI
<thelema_> vext01: the docs for the package don't say how to use it in the toplevel, they say how to code for it in compiled code.
<hcarty> thelema_: But sadly not as much upstream
<thelema_> hcarty: yes little, incompatible, islands of sanity
<hcarty> thelema_: Which makes for an ocean of insanity. Hooray for odb!
<vext01> ^ is what i was trying to run
<vext01> as a test
<thelema_> yup, this is writt to be compiled
<vext01> i was running "ocaml test.ml" where i had saved the example to "test.mk"
<vext01> test.ml
<thelema_> ocamlfind ocamlc -package glpk -linkpkg example.ml -o example
<vext01> is this incorrect (the top level is not being used here)
Cyanure has joined #ocaml
<vext01> thelema_: i see
<vext01> how comes i dont have to do this for say, list, where i just do "open List;;"?
<thelema_> vext01: list is in the stdlib
<thelema_> the path that its list.cmo file is located is automatically searched in
<thelema_> on my todo list is to make a magic comment parser so that the information about how to compile a file is located *in that file*
<thelema_> as opposed to having to write terrible things like the above ocamlfind command
<vext01> yes, its a bit odd i must say
<thelema_> it's a tiny bit better than C/C++, but nowhere near as nice as Perl, Python, Ruby, etc. even Java (sometimes)
<vext01> yeh, I expect arcane from C :P
<thelema_> yup, everyone puts up with it with C, but noone really wants to put up with it in OCaml.
<thelema_> also, C's #include mechanism to some degree makes non-linktime dependencies much easier
<thelema_> so maybe not even as good as C/C++
<vext01> at the risk of sounding naive, why does open not invoke findlib?
<vext01> then you could have one interface
<hcarty> thelema_: It already exists, at least to some extent, in ocamlscript
<hcarty> vext01: You can't always tell which .cma/.cmxa to load based on a module's name
<vext01> i imaggined there would be a complication
Kakadu has joined #ocaml
<hcarty> thelema_: Perl has a similar issue, but (arguably much) better out of the box defaults
<hcarty> That said, even Perl needs some help - cpanm is miles ahead of the default cpan for easy of use
<hcarty> And you still may need to setup some per-.pl configuration or environment variables to make everything play nicely
<adrien> I haven't managed to use cpan :-)
<hcarty> adrien: cpanm... skip cpan entirely :-)
<vext01> cpan was a nice idea, but usually failed on non-linux systems where native code had to be built
<adrien> hcarty: noted ;-)
<hcarty> There is something of a similar issue in Perl-land to what exists in OCaml-land. The 'right' tools exist, but not everyone uses or knows about them.
<hcarty> vext01: I think that's part of what Strawberry Perl is meant to address. I don't know how successful it is.
eni has joined #ocaml
<vext01> hcarty: ok i dont know about that
<hcarty> vext01: And 'usually failed on non-linux systems' seems to be a very common issue in programming languages
<vext01> ye
<hcarty> Not a good thing perhaps, but a common thing.
Submarine has quit [Quit: Leaving]
<vext01> thelema_: would there be a way to compile the test program inside the build dir without the package being installed
<vext01> this would allow me to write a regression test you see
<vext01> no worries if its not easy
<adrien> I haven't read the backlog but typically, you'd install the package, but locallu
<adrien> locally*
<adrien> it's cleaner and easier imho
<adrien> (for that, ocamlfind can use a number of environment variables)
<vext01> ill have a look at the ocamlfind library shortly
<vext01> thanks
<mrvn> oasis does that for you quite nicely.
<eni> i was doing a lambda evaluator just for fun, http://paste.pocoo.org/show/581974/ , i don't like the Application terme * terme , for the moment i can't do stuff like ((λx.λy.x*y) 1 2) but i can do stuff like (λx.((λy.x*y) 2) 1). Can you guys give me a hint on how to proceed (Changing Application to terme * terme list ?)
<mrvn> vext01: if you advanced to something complex enough to need a build system then do check out oasis.
<mrvn> eni: why not change your parser to curry things implicitly?
<eni> mrvn, can you be more explicit please?
<eni> and for the moment there's no parser.. (i'm not reading text but constructing an AST directly)
Tobu has quit [Ping timeout: 260 seconds]
<pippijn> what's a "terme"?
<pippijn> what language is that?
<eni> french
<vext01> mrvn: im working inside openbsd ports tree
<pippijn> french people and their french code..
<vext01> packages can have regression tests, but they are more suited to "make check" type tests
<eni> pippijn, i'm not french :)
<pippijn> is Number also french?
<eni> pippijn, apart terme everything else is suposed to be english
<pippijn> mixed people and their mixed language code..
<eni> haha
<pippijn> eni: why is it called terme?
<mrvn> eni: I think your problem is that your Application(l, t) does not first evaluae l and t before applying them.
<eni> mrvn, you are right.
<mrvn> # evaluate (Application ((Application ((Lambda("x",Lambda("y",Multiplication(Var("x"), Var("y"))))),Number(3))), Number(2))) [];;
<eni> I'm implying that t is a number.
<mrvn> Exception: Match_failure ("", 39, 24).
<mrvn> eni: l is an Application here, not a Lambda and you need to evaluate that first to get a Lambda expression to apply to
<mrvn> eni: secondly you can't evaluate a lambda unless it is bound by an application.
smerz has joined #ocaml
<mrvn> # evaluate (Application ((Lambda("x",Lambda("y",Multiplication(Var("x"), Var("y"))))),Number(3))) [];;
<mrvn> Exception: Failure "HERE".
<mrvn> That should return Lambda("y",Multiplication(Number(3),Var("y")))
<eni> yep
Tobu has joined #ocaml
<mrvn> If you fix those two then you have lambdas as first class values and then I think ?x.?y.(x*y) 2 3 will evaluate
<thelema_> vext01: does glpk use ocamlbuild?
<vext01> i think so
<vext01> there is a OMakefile
<jathd> eni: wouldn't it be simpler to have 2 different types, one 'terme' and one 'value'? That may help the type-checker help you...
<thelema_> vext01: nope, that's omake.
<thelema_> vext01: if it were ocamlbuild, there'd be _tags files and/or myocamlbuild.ml
<eni> hmm, probably, but i think it can work if i do the modifications mrvn told me.
<thelema_> vext01: you should be able to add "-I path/to/build_dir" to the compile command of example file to get it to compile from source tree
<vext01> and maybe some linkage flag
<vext01> there is a shared object built
<thelema_> vext01: yes, for linking, make sure to link in the .cma/.cmxa file (bytecode/native)
<mrvn> # evaluate (Application ((Lambda("x",Lambda("y",Multiplication(Var("x"), Var("y"))))),Number(3))) [];;
<mrvn> - : terme = Lambda ("y", Multiplication (Var "x", Var "y"))
<mrvn> eni: you need something more to replace the "x" when it is bound
<eni> right now i have this
<eni> # evaluate (Application ((Lambda("x",Lambda("y",Multiplication(Var("x"), Var("y"))))),Number(3))) [];;
<eni> - : terme = Lambda ("y", Multiplication (Number 3, Var "y"))
<vext01> thelema_: are you referring to ccopt and cclib?
<thelema_> vext01: no
<thelema_> when you build glpk, it should generate a .cma and a .cmxa file
<thelema_> these are what the ocaml compiler needs to link an executable.
<thelema_> For compiling, it needs the .cmi files for each module you use.
ggherdov has joined #ocaml
<mrvn> eni: not with what you pasted
<eni> with this one, i changed one line or two.
<eni> Application(Application.. still giving bad match.
<eni> i have to change my | Application in evaluate.
<mrvn> | Application(l, t) ->(
<mrvn> let l = evaluate l env in
<mrvn> let t = evaluate t env in
<mrvn> # evaluate (Application ((Application ((Lambda("x",Lambda("y",Multiplication(Var("x"), Var("y"))))),Number(3))), Number(2))) [];;
<mrvn> - : terme = Number 6
<eni> yep
<eni> thanks.
<vext01> thelema_: ok, well i am in the dir with cmi/cma/cmo files
<vext01> there is also a META file
<vext01> perhaps i can get away with adding the cwd
<eni> still doesn't look "good code" to me, those matches inside matches are kind of ugly probably i could refactor that.
<mrvn> eni: your terme type is to general. An Application doesn't accept terme as first argument, only Lambda or Application (which returns a Lambda when evaluated)
<eni> is there a tutorial on how to parse text using ocaml?
<eni> ocamlyacc/lex?
<pippijn> vext01: do you use ocamlbuild?
<pippijn> eni: yes, but they are not very good
<eni> mrvn, you're suggestion to create 2 different types like jathd did ?
<mrvn> eni: maybe.
<eni> ok, i'll see this as well,.
<vext01> pippijn: no, im just using someone elses project which used omake
<pippijn> ah ok
<mrvn> eni: or more
<thelema_> vext01: if you compile in the dir with the cmi/cma/cmo files, then you only need to add the .cma for linking, and don't need any include
<vext01> sorry, im getting confused by what is meant by linking here
<vext01> -linkpkg?
<thelema_> vext01: when you compile C (and ocaml), there's two steps: 1) compile source files into .o (.cmo) 2) link them together into an executable
<thelema_> if you're doing this in a single command, you need all the arguments for both.
<thelema_> (well, minus the -c)
<vext01> ok, this is synonymous to C
<thelema_> so to compile example.ml into example and link in the code from glpk, use the command
<thelema_> ocamlc example.ml -o example glpk.cma
<thelema_> or for native compilation, ocmalopt example.ml -o example glpk.cmxa
<mrvn> eni: When I looked into GADTs that seem to be a great help for your problem and would prevent your from creating bad terme values.
<thelema_> you have to specify the cma/cmxa "library", otherwise when ocaml goes to link example... well, actually it'll just pick the .cmo files that are already in the current directory... n/m then
<vext01> i see
<vext01> well it is unable to find glpk, remember it has not been installed at this point
<thelema_> ocamlc example.ml -o example (it'll look for .cmo and .cmi files for every module you use, and the search path includes the current directory
<thelema_> is there a glpk.cmi?
<thelema_> unless... packing...
<vext01> there is
<vext01> adding -c makes the object file ok
<thelema_> ok, so no problem compiling.
<thelema_> when you compile, you get a example.cmo, yes?
<vext01> yaha
<mrvn> is there a glpk.cmo?
<thelema_> ocamlc example.cmo glpk.cma -o example
<mrvn> ocamlc glpk.cma example.cmo -o example
Kakadu has quit [Quit: Konversation terminated!]
<vext01> mrvn: there is
<mrvn> thelema_: last I checked the order mattered
<thelema_> but if there were C stubs involved, you need to use the .cma/cmxa so it links them in
<thelema_> mrvn: you're right.
<thelema_> ocamlc glpk.cma example.cmo -o example
<vext01> i have to add a linker flag, let me figure out how
<mrvn> vext01: just try it on the shell first
<thelema_> ? linker flag? for the linking by gcc?
<eni> mrvn, GADTs?
<mrvn> eni: new thing for the next ocaml release. Generic Algebraic Data Types. Allows you to specify dependent types.
<thelema_> mrvn: not quite dependent types.
<vext01> 2% ocamlc glpk.cma example.cmo libglpk_stubs.a -o example
<vext01> /usr/bin/ld: cannot find -lglpk_stubs
<vext01> collect2: ld returned 1 exit status
<vext01> looks like i need -dllib, but im not having success
<thelema_> ah, maybe you will have to go back to not using the .cmxa and linking in all the individual .cmo files you need plus the -cclib libglpk_stubs.a
<thelema_> or maybe just a -ccopt -L.
<thelema_> (or wherever the libglpk_stubs.a file is)
alvis has joined #ocaml
<mrvn> yeah, looks to me like it can't find the libglpk_stubs.a to me, too.
<vext01> -ccopt -L. works
<vext01> great
<mrvn> vext01: you should be able to drop the libglpk_stubs.a from the cmd.
<vext01> i did :)
<mrvn> And now you've get to figure out how to tweak your build system to do what you did manually.
<vext01> indeed
<vext01> what solution did you get btw
<vext01> OPTIMAL SOLUTION FOUND
<vext01> Z: 733.333 x0: 33.3333 x1: 66.6667 x2: 0
<|Lupin|> thelema_: thanksa lot for the push !
landonf has joined #ocaml
<thelema_> |Lupin|: you're welcome.
<|Lupin|> eni: for your evaluator project: you may want to have a look to alphaCaml...
<eni> thanks |Lupin|
<thelema_> vext01: I get the same solution.
<vext01> great
eni has quit [Ping timeout: 245 seconds]
<vext01> thelema_: mrvn: adrien : this seems to work
<vext01> see the "do-regress" target
<thelema_> I see. That looks like it would work, but instead of compiling inside {WRKSRC}/src, maybe it'd be better to -L{WRKSRC}/src and -I {WRSRC}/src
<vext01> fair point
<thelema_> that said, why fix it if it ain't broken.
Zedrikov is now known as NamelessOne
<|Lupin|> 'dnight eveybod.Thaks a lot for your work thelema_
|Lupin| has quit [Quit: leaving]
thelema_ is now known as thelema
<vext01> thelema: thoe only other thing that bothers me is this ld.conf hack
<vext01> you can see it in the Makefile
<vext01> there does not seem to be a ld.conf on my system
<vext01> hence i bodged it
<vext01> ok i see
<thelema> vext01: worked out?
<vext01> i think it osnt required
glguy has joined #ocaml
<vext01> isnt
<thelema> correct, it shouldn't be required
<vext01> so that would be a bug in the ocaml-glpk build system
<thelema> yes
emmanuelux has joined #ocaml
<vext01> thelema: although he does make a shared object
<thelema> which gets installed in ocamlfind's stublibs, so it doesn't need any special ld.conf settings (assuming findlib is installed properly)
<vext01> it doesnt get installed in the right place ;)
<vext01> /usr/local/lib/ocaml/site-lib/glpk/dllglpk_stubs.so
<thelema> really? it did on my system, I think...
<vext01> can you have a look
<thelema> i get a libgtpk_stubs.a file in my .odb/lib/glpk directory
<thelema> and the dllglpk_stubs.so in my .odb/lib/stublibs dir
<thelema> maybe findlib does something different on bsd
<vext01> do you think i should move it?
<vext01> to do so is trivial
<thelema> what paths are in your ocaml ld.conf file?
<vext01> there isnt one :P
<vext01> i did not do that porting
<vext01> wait
<thelema> and glpk works from findlib?
<vext01> i lied
<vext01> /usr/local/lib/ocaml/ld.conf
<thelema> yes, that one
<vext01> yeh and stublibs is there
<vext01> im suprised glpk is found
<vext01> i think it should be moved
<thelema> the .so file should be in a dir listed in the ld.conf
<vext01> according to the page i pasted
<vext01> /usr/local/lib/ocaml/stublibs
<vext01> is prefferred
<thelema> sure - my config is a bit unusual because I'm using odb for a local install of packages
<vext01> ok don
<vext01> e
<adrien> grrrrr
<adrien> I need to know if a module is the "main" one or not
<adrien> and call a function only if it is
<thelema> adrien: inspect Sys.argv.(0)?
<adrien> I guess I should rather create another .ml which reads only "let () = Yypkg.main ()"
<thelema> ocaml doesn't have a concept of "main" module
<adrien> thelema: too brittle unfortunately
<adrien> but creating a new file should do it
<thelema> all code in all modules is run in link order
<thelema> err, all toplevel expressions are evaluated
<adrien> I would have liked to be able to list the modules that have been linked in
<adrien> (now, the worst thing: I need to find a name for the new file! ='( )
<thelema> I guess the linker could save this somewhere and make it available to the runtime...
<adrien> basically, my use-case is "if GUI module linked in, don't run $this"
<adrien> should be worth asking as a feature-request
<vext01> thelema: thanks for your patience
<thelema> adrien: can you implement that yourself?
<thelema> have the gui module modify a bool ref to indicate that it's linked in.
<thelema> vext01: you're welcome
<adrien> the gui module initialization will run later
Cyanure has quit [Remote host closed the connection]
<adrien> basically, it's the one which gets initialized the last
<thelema> so just have a flag "initialization done" which is set by the first module that can do initialization
<thelema> err, main done
<adrien> what's nice with main() in C is that you know where it is
<adrien> you know the entry point to the program
<adrien> if I make the "Yypkg" module auto-initialize (which I could), I find it not obvious
<adrien> there are really two sets of _big_ initialization codes
<adrien> proof is that I had a bug with a double initialization and didn't find it immediately
<thelema> so just have the initialization code register itself somewhere instead of running itself
<adrien> (now, I'm coming back to the code, 15 months later, and I find it in a few minutes; experience helps but still)
<thelema> and have a single main in a third module that looks at what initialization code has been registered and runs the right one
<adrien> yeah, I'd need another module ;-)
Ptival has quit [Quit: leaving]
Ptival has joined #ocaml
<adrien> rewrite src/yypkg/yypkg.ml (99%)
<adrien> rename src/yypkg/{yypkg.ml => yypkg_top.ml} (99%)
<adrien> with yypkg.ml with only "let () = Yypkg_top.main ()" and the GUI code calls "Yypkg_top.main ()", but the Yypkg module is only linked in non-graphical mode
<adrien> it's fairly simple... for someone who knows who module initialization is done; otherwise, I find it horribly complicated and kludgy
<adrien> if List.exists ((=) "Gtk") Whatever.linked_in_modules then Yypkg.main ()
<_habnabit> (List.mem ?)
<adrien> heh, true =)
milosn has quit [Read error: Connection reset by peer]
milosn has joined #ocaml
<adrien> night
err404 has joined #ocaml
ggherdov has quit [Ping timeout: 276 seconds]
countdown has quit [Remote host closed the connection]
err404 has quit [Quit: Ex-Chat]
tetsuya_ has quit [Quit: Leaving]
eni has joined #ocaml
Xizor has quit [Ping timeout: 260 seconds]
benozol has joined #ocaml
zorun has quit [Read error: Connection reset by peer]
benozol has quit [Quit: Konversation terminated!]
zorun has joined #ocaml
Tobu has quit [Remote host closed the connection]
Tobu has joined #ocaml
<eni> how often do you use functors?
emmanuelux has quit [Remote host closed the connection]
emmanuelux has joined #ocaml
<thelema> eni: often.
eni has quit [Quit: Leaving]