rwmjones changed the topic of #ocaml to: Discussions about the OCaml programming language | http://caml.inria.fr/ | Grab Ocaml 3.10.1 from http://caml.inria.fr/ocaml/release.html (featuring new camlp4 and more!)
<bla> ikatz, hm? (I like to use heaps for p. queues.)
<ikatz> i'm really not too concerned what specific structure i use as long as i can be sure it can handle a fold operation
<ikatz> because ... as i'm recursing, i need to make sure that the location in the structure currently being visited by the parent won't change
<ikatz> in other words, all changes to the tree happen to the "right" of my current path
<ikatz> i'm currently trying to do a proof for whether AVL trees satisfy that, i can check out the heap one too
<ikatz> (its not looking good for the AVL...)
seafood_ has quit []
Yorick has quit [Remote closed the connection]
onigiri has joined #ocaml
onigiri has quit []
postalchris has quit ["Leaving."]
jbu311 has joined #ocaml
<jbu311> hi all, I'm trying to delete a specific element toBeDeleted from a list lst: let remove toBeDeleted lst = fold (fun acc elt -> if toBeDeleted = lst.hd then lst.tl else acc :: lst.hd)[] lst in
<jbu311> doesn't seem to work though, anyone know why?
<jbu311> I guess I want to return acc which I'm not doing either
<jbu311> it juts says unbound fold
<thermoplyae> well, it should be List.fold_left, judging by the way you have your anonymous function set up
<jbu311> oh
<jbu311> yes, i think so
<thermoplyae> you should be using List.fold_right (and reversing the order of the arguments) if you don't want to reverse your list as you're building it
<thermoplyae> actually, it looks like i didn't read carefully enough
<thermoplyae> :: has type 'a -> 'a list -> 'a list
<thermoplyae> [1;2;3;4;5] :: 0 doesn't make much sense
<thermoplyae> "let remove target lst = List.fold_right (fun x y -> if x = target then y else x :: y) lst []" is more what you're going for
<jbu311> I need to look up fold left and right :)
<thermoplyae> probably
<thermoplyae> a refresher on how functional lists work looks like it wouldn't hurt either
<ikatz> ok... strange problem with types http://pastebin.be/8791
szell` has joined #ocaml
<ikatz> a node is (_, node option, action, _, _, _)
<ikatz> the compiler doesn't seem to agree
<thermoplyae> you're calling soln_h recursively
<ikatz> apparently options don't like being referred to recursively?
<thermoplyae> hmm
<thermoplyae> i was going to point that out, but yeah, that's nonsense
<ikatz> well, what i'm trying to do is record the path to a solution in a search
<ikatz> so each node has a reference to the parent node as the second member of the tuple
<ikatz> i made that an option because the top node has no parent
<thermoplyae> apparently option types can't be cyclic. that is kinda weird
<jbu311> are there not remove functions similar to :: and @?
<thermoplyae> something like type rectype = (rectype * int) option doesn't work
<thermoplyae> but type rectype = Nothing | Something of (rectype * int) does
<ikatz> crap... what could i use instead to indicate a null parent?
dibblego has joined #ocaml
<thermoplyae> i dunno. the option paradigm seems like the way to go, just declare your own variants
<thermoplyae> complain loudly to someone in here that actually has authority on these matters :)
<ikatz> jbu311: "let remove mylist = match mylist with [] -> raise empty | _::tail -> tail"
<jbu311> what's raise?
<ikatz> raise an exception (error case)
<ikatz> alternatively, you could options:
<jbu311> ah
<ikatz> let remove mylist = match mylist with [] -> None | _::tail -> Some tail
dibblego has quit [Client Quit]
<ikatz> we all like some tail :)
<jbu311> yes
<ikatz> jbu311: now that i think about it, it seems odd that you would remove the head of the list without looking at it
<ikatz> generally what you would do is "match mylist with [] -> (* something *) | head::tail -> (* do something with head and return tail *)
<jbu311> yeah
<jbu311> that looks good
<jbu311> i'm trying to figure out this whole fold business
<ikatz> where are you stuck?
seafood_ has joined #ocaml
<ikatz> like... the concept of fold, or getting it to compile?
<jbu311> i understand the concept, i'm trying to figure out the syntax
<jbu311> though what I'm trying to do definitely doesn't require fold and I'm probably spending too much time trying to implement it using fold
<ikatz> are you using List.fold_left or List.fold_right?
<jbu311> is fold defaulted to left?
szell has quit [Read error: 110 (Connection timed out)]
<jbu311> I'm just using "fold"
<ikatz> there is no "default"... are you using SML or ocaml?
<ikatz> actually, the other possiblity is that you've written your own fold function. is that the case?
<jbu311> ocaml
<jbu311> yes
<ikatz> aah
<ikatz> it depends on how you wrote it
<jbu311> now i'm more confused than ever
<ikatz> fold_left is tail recursive, fold_right is not
<jbu311> that means very little to me
<ikatz> ok :)
<jbu311> gimme one sec i'll show u what I have
<ikatz> how does your fold function terminate?
<ikatz> yes :) that would help
<jbu311> let remove toBeDeleted lst = List.fold_left (fun acc elt -> if toBeDeleted = lst.hd then acc else lst.hd :: acc)[] lst in
<jbu311> I haven't tried thermoplyae's version yet, still trying to get my own to work
<thermoplyae> that's closer to being correct, but you're missing the point of the 'elt' in the anonymous function
<jbu311> yes, i am
<jbu311> :(
<ikatz> elt is the piece of the list that you're working on at that moment
<thermoplyae> fold works by popping something off the list, doing something with it, and then continuing to walk down the list
<jbu311> yeah
<thermoplyae> right, and elt is that piece, not List.hd lst
<jbu311> OH
<thermoplyae> (which is what it looks like you meant)
<jbu311> that makes sense
<jbu311> I knew it had something to do with the popped element and not hd
<jbu311> thanks
<jbu311> I assume this is correct now that it's not giving me errors
<jbu311> let remove toBeDeleted lst = List.fold_left (fun acc elt -> if toBeDeleted = elt then acc else elt :: acc)[] lst in
<ikatz> yes
<jbu311> hooray
<jbu311> thanks guys
<ikatz> still curious about fold_left vs fold_right?
<thermoplyae> i want to emphasize again that that will reverse the input list :)
<thermoplyae> but other than that it'll behave like you expect
<jbu311> I am pretty sure I understand fold_left and right
<ikatz> i meant in terms of being tail recursive
<jbu311> but considering thermoplyae is saying it'll reverse the input list, I am guessing I dont understand it
<ikatz> right... so,
<jbu311> i would expect fold_right to have reversed it
<jbu311> hmm
<jlouis> if [x1; x2; x3] is your list, # is your operator and 0 your initial element, then fold_left can be seen as (((0 # x1) # x2) # x3)
<jbu311> yes
<jbu311> understood
<jbu311> but
<ikatz> so in your case, the first element you process becomes the tail of your ouptut list
<jlouis> fold_right puts the parenthesis right-associative (and then also the initial element)
<jbu311> ikatz: but i use :: which puts the popped element at the beginning of the accumulator
<ikatz> that's right
<jbu311> heh...hmm
<ikatz> then the next one goes on top of it ... etc
<ikatz> so its efficient, because at any point you're only looking at the top of your input list and the top of your output list
<jbu311> ya
<jbu311> still not seeing where it'd be reversed, but i'll prove that to myself in just a second
<ikatz> fold_right opens the entire list in memory, until it gets to the last element
<ikatz> then it backtracks
<ikatz> well, you can do it yourself with playing cards
<ikatz> say you're looking for a specific card to remove from the deck
<ikatz> so you put the deck in front of you, face up
<ikatz> and you pick up a card, and if its not the one you want to remove, you put it in a second pile face up
<ikatz> so the first card you pick up becomes the bottom of your new pile
<ikatz> so that's why fold_left is reversing your order
<jbu311> interesting...it didnt remove the element BUT it did reverse my order
<ikatz> what datatype is stored in the list?
<jbu311> string
<ikatz> weird... what you have looks right
<jbu311> q := remove "blahblah" !q;
<jbu311> where q is a referenced object
<ikatz> remove "foo" ["bar"; "pizza"; "foo"; "pants"];;
<xavierbot> Characters 1-7:
<xavierbot> remove "foo" ["bar"; "pizza"; "foo"; "pants"];;
<xavierbot> ^^^^^^
<xavierbot> Unbound value remove
<ikatz> oh sweet!
<ikatz> let remove toBeDeleted lst = List.fold_left (fun acc elt -> if toBeDeleted = elt then acc else elt :: acc)[] lst;;
<xavierbot> val remove : 'a -> 'a list -> 'a list = <fun>
<ikatz> remove "foo" ["bar"; "pizza"; "foo"; "pants"];;
<xavierbot> - : string list = ["pants"; "pizza"; "bar"]
<ikatz> see? it works!
<jbu311> lol didnt work on my end
<jbu311> though it is reversing
<jbu311> hey
<jbu311> it did work, though for some reason I cant put the literal into the first param
<jbu311> for instance i do remove "calorimeter" and it doesnt remove it
<ikatz> can you paste any of that code in here?
<jbu311> but remove temp (whose value is calorimeter) works
<jbu311> ikatz: don't worry about it, I'm guessing its a small problem
<jbu311> i can get it
<jbu311> I'm assuming its that the values in the list are stored with a \n at the end
<ikatz> :)
<jbu311> thanks
<jbu311> and i see why its reversing now, i'm a retard
Cosmos95 has joined #ocaml
p3l has quit [Read error: 113 (No route to host)]
thermoplyae has quit ["daddy's in space"]
Cosmos95 has quit []
StoneNote has quit []
shortcircuit_ has joined #ocaml
shortcircuit_ has quit [Read error: 104 (Connection reset by peer)]
thermoplyae has joined #ocaml
psykon has joined #ocaml
psykon has left #ocaml []
AxleLonghorn has joined #ocaml
<jbu311> ikatz: are you still there?
<ikatz> hi
<jbu311> hi :)
<jbu311> u remember the remover function i wrote?
<ikatz> yes
<jbu311> would that work with a list of tuples?
<jbu311> like, can one tuple = another?
<jbu311> or would I have to test both their members
<jbu311> 2-tuple
<ikatz> you would have to write your own comparison function
<jbu311> rats
<ikatz> well... this is where functional programming can help a little
<jbu311> reaaaallly..
<jbu311> lol i've been doing imperative programming like most of the way through this program
<ikatz> if you can follow this, you'll really get the beauty of ocaml
<jbu311> okay
<ikatz> pass a comparison function as an argument to your remove function
<ikatz> similar to how you pass that anonymous function to list.fold_left
<ikatz> so you could say :
<jbu311> is this higher-order functions?
<ikatz> yes
<jbu311> are these*
<ikatz> let remove compare tbd lst = List.fold_left (fun acc elt -> if compare tbd elt then acc else elt::acc) [] lst;;
<xavierbot> val remove : ('a -> 'b -> bool) -> 'a -> 'b list -> 'b list = <fun>
<ikatz> so you would do something like:
<ikatz> remove (=) "foo" ["bar"; "pizza"; "foo"; "pants"];;
<xavierbot> - : string list = ["pants"; "pizza"; "bar"]
<jbu311> are tbd and lst the params to compare or the params to remove?
<ikatz> tbd = toBeDeleted
<jbu311> no i meant
<jbu311> are they the params to the compare function or the params to the remove function
<ikatz> tbd and elt are the params to the comapre function
<ikatz> oh i see what youre saying
<ikatz> remove takes 3 params: compare, tbd, and lst
<jbu311> ok
<ikatz> functions always take as many arguments as they see in front of them
<jbu311> ah, that's really cool
<ikatz> to do it the other way would look like "remove (compare tbd lst)"
<jbu311> I'll kinda forget what you wrote and try it on my own
<thermoplyae> not to interrupt, but = will do a structural equality over tuples (i.e. (1, 2) <> (1, 3) and (2, 1) = (2, 1) are both true)
<thermoplyae> using a filter is smart too
<ikatz> no kidding!
<thermoplyae> == does physical equality, = does structural
<thermoplyae> similarly for != and <>
<jbu311> wait
<ikatz> hah
<ikatz> jbu311: if you really want to forget what i said, look up list.filter :)
<jbu311> so (2, 1) == (2, 1) is true and (2, 1) == (3, 1) is false?
<thermoplyae> no, they'll probably both return false
<ikatz> (2, 1) == (2, 1);;
<xavierbot> - : bool = false
<ikatz> (2, 1) = (2, 1);;
<xavierbot> - : bool = true
<thermoplyae> :)
<jbu311> let me look up structural vs. physical
<ikatz> i am really diging this xavierbot
<thermoplyae> jbu: if you know C, it's the difference between "abc" = "abc" and strcmp("abc", "abc")
<jbu311> oh
<jbu311> address = physical
<jbu311> and structural, i would guess, is maybe if two objects have the same members and are typed the same?
<thermoplyae> more or less
<jbu311> haha ok,
<jbu311> so bottom line is i have to write a comparator?
<jbu311> or use filter?
<ikatz> does that just work for primitive types?
<ikatz> like, as long as the tuples contain stuff that's defined for "=" then it works?
<thermoplyae> yeah
<thermoplyae> same with lists and variant types
<thermoplyae> it works for < and > too, using lexicographic ordering
<ikatz> jbu311: you can use list.filter similarly to the way you are using fold
<ikatz> whether you write a comparator depends on whether you will have something besides ints, floats, and strings in your tuples
<jbu311> string * string
<ikatz> ("foo", "bar") = ("foo", "bar");;
<xavierbot> - : bool = true
<ikatz> so it looks like your original function would work
<jbu311> so basically filter is like an AND of two lists?
<ikatz> but mess around with list.filter
<jbu311> i mean
<ikatz> List.filter;;
<xavierbot> - : ('a -> bool) -> 'a list -> 'a list = <fun>
<jbu311> union
<ikatz> nope
<jbu311> no
<jbu311> oops
<jbu311> intersection
<jbu311> lol
<ikatz> the way to read the signature is:
<AxleLonghorn> anybody know how the for and while loops are implemented in the compiler?
<ikatz> the part after the last "->" is the return value
<jbu311> yeah
<ikatz> so it takes a function an a list as args
<jbu311> oh i see
<AxleLonghorn> I heard a rumor that the for-loop is just syntactic sugar for unrolling the loop, is this true?
<ikatz> no clue
<AxleLonghorn> k
<ikatz> but then, i know dick about the compiler
<AxleLonghorn> :)
jderque has quit [Read error: 113 (No route to host)]
bzzbzz has quit ["leaving"]
mwc has joined #ocaml
AxleLonghorn has left #ocaml []
<jbu311> guys, is failure "nth" just an out of bounds exception?
<thermoplyae> yes
psykon has joined #ocaml
<psykon> Hello
<jbu311> if I haven't previously declared k...when I do for k = 0 to 9 do ... done; in the "..." is there a way to increment k?
<thermoplyae> i don't believe so
<jbu311> thermoplyae, what if I do declare it? or what if I declare it as a reference
<ikatz> thats generally not how its supposed to work...
<thermoplyae> that's not really how ocaml works
<thermoplyae> yeah
<thermoplyae> it'll instantiate a new k each time through the loop that shadows whatever previous k existed
<ikatz> or to put it another way, there is probably a more apt method of solving your problem
<thermoplyae> certainly! why use an iterative structure when you can use a flexible functional structure?
<jbu311> groan
<jbu311> okay
<jbu311> basically I'm trying to iterate over a list I'm deleting from
<ikatz> ok
<jbu311> I could hack it with a while loop
<jbu311> any functional methods that you guys know of that'd work?
<ikatz> well, what are you doing to the list besides deleting?
<ikatz> there are generally 3 "loop" type functions in ocaml structures:
<ikatz> fold (left or right), iter, and map
<jbu311> hmm
<ikatz> iter says "for each element in this structure, run this function on it and return nothing"
<jbu311> i dont see an obvious way to use any of those to get this to work
<ikatz> map says "give me a new structure with each element of the old structure being modified by my function"
<jbu311> hrm
<ikatz> and fold says "give me something new that is based on the structure"
<jbu311> oh
<jbu311> hmm
<tsuyoshi> if you're iterating and deleting you want fold
<ikatz> let mylist = [8; 6; 7; 5; 3; 0; 9];;
<xavierbot> val mylist : int list = [8; 6; 7; 5; 3; 0; 9]
<ikatz> List.iter begin fun x -> print_int x; print_string " is my favorite number\n"; end mylist;;
<xavierbot> 8 is my favorite number
<xavierbot> 6 is my favorite number
<xavierbot> 7 is my favorite number
<xavierbot> 5 is my favorite number
<xavierbot> 3 is my favorite number
<xavierbot> 0 is my favorite number
<xavierbot> 9 is my favorite number
<xavierbot> - : unit = ()
<ikatz> List.map begin fun x -> x * 10 end mylist;;
<xavierbot> - : int list = [80; 60; 70; 50; 30; 0; 90]
<jbu311> there is a lot of content within my for-loop, dont folds usually have just a few lines of code in them?
<ikatz> the short answer is no
* jbu311 groans again
<jbu311> oh...i see how I'd use fold
<ikatz> the long answer is that you can put as much code as you need to in there to get the job done :)
<jbu311> but it'd be easier to hack it with a while loop :)
<ikatz> what's the goal of the function you're writing?
<jbu311> ikatz: its a topological sort, one part of it requires me to iterate over edges of a graph and delete ones that are no longer needed
<ikatz> you could use either list.fold or list.filter
<ikatz> if the criteria for deletion is known for all edges when you start the function, use filter
<jbu311> there's no break command in ocaml?
<ikatz> if it depends on other entries in the list, use fold
<ikatz> you won't need it if you use fold properly
<jbu311> but there isnt a break?
<ikatz> fold is really your friend, even though it takes alittle getting used to
<ikatz> nope :( but you can raise exceptions
<thermoplyae> that is actually sort of a valid point
<thermoplyae> folding can make some things linear in the size of the input list instead of in some other element (like using fold_right to take the last n elements of a list)
<thermoplyae> you can get around it with exceptions, but :(
<ikatz> instead of updating several variables within the while loop, consider making a tuple of those values in the function that you fold
<ikatz> for example, filtering some numbers out of a list that are lower than the running average
<ikatz> in C, you'd have a while loop and you'd keep track of the number of items seen as well as the current average... and you'd delete items that were below that average
<ikatz> in ml, you'd fold a tuple of (items, avg, out_list) into the input list
<jbu311> yeah I see the power in fold
<jbu311> sigh, here goes a pathetic attempt at folding again
<ikatz> i guess i'm trying to sugar-coat the fact that you're going to have to learn it one way or the other eventually :)
mwc has quit [Read error: 113 (No route to host)]
<jbu311> recursion's never been my strong point
<ikatz> it takes getting used to.
<jbu311> thank god ocaml has a mem function...if not it looks like I'd have to do a fold within a fold
<ikatz> not unheard of... i'm doing that right now in a depth-first search algorithm
<jbu311> ikatz: you're right, it really isnt too bad (as far as I can see)
<ikatz> my brain melted the first time i was forced to use it
<ikatz> aah, good times :)
<ikatz> seriously though, the one trick that will save you a brain-melting is in the case where you are folding a fold
<ikatz> sometimes you have to wrap the fold function in your own function either to put the arguments in a different order or to fill some of them in automatically
<ikatz> i was getting really frustrated because i couldn't see the way to make the exit case and the recursive case "meet"
<jbu311> ...
<ikatz> that's all, really
<ikatz> classmate pointed out that i could make my own function that contained List.fold but put the arguments in an order that matched the rest of my function
<jbu311> I just had a hard time understanding what you had to do
<jbu311> sounds like I wouldnt want to do it
<jbu311> you know how I end the fold with like ) accumulator lst in
<ikatz> yes...
<jbu311> when I refer to my lst within the fold declaration
<jbu311> is that basically the list with some elements popped off of it?
<jbu311> like if I've folded twice and refer to lst in my fold declaration it will be the original list missing the first two elements?
<ikatz> hmm.. can you paste it in here again?
<jbu311> also...I have a nested if statement in my fold, is that ok?
<jbu311> it doesnt look right...
<jbu311> it looks like the parser couldn't handle it
<ikatz> oh actually i can answer this
<ikatz> lst happens outside the declaration of the function that you fold
<jbu311> k..
<ikatz> so this is exactly like my brain-melting anecdote
<jbu311> but when I refer to it inside the declaration , is it just the list with some stuff popped off?
<ikatz> well that's what i'm saying
<ikatz> inside the declaration, it has no clue what lst is
<ikatz> actually i could be mis-speaking... i'm making assumptions about what your code looks like
<jbu311> heh...
<jbu311> should I paste it?
<ikatz> please do :)
<jbu311> sigh
<jbu311> u guys like this language?
<thermoplyae> adore it
<ikatz> you get used to it :) it starts saving you a lot of typing
<jbu311> I assume I'll have to spend a large initial amount of typing to first learn the language before I can break even on the "saving typing" thing
<tsuyoshi> jbu311: what is m?
<jbu311> m is a particular vertex that that is the vertex to which the edge points
<jbu311> wait
<jbu311> that didnt make any sense
<jbu311> m is a particular vertext to which the edge points
<jbu311> vertex*
<ikatz> so if i'm reading this right
<jbu311> I realize theres a bunch I'm leaving out
<ikatz> wait lemme back up...
<ikatz> mem_match_first !temp
<ikatz> what is the function comparing?
<jbu311> compares param1 to the first member of param2
<jbu311> let mem_match_first e (sa, _) = (e = sa) in
<ikatz> oh ok first as in tuple not in list :) gotcah
<jbu311> ja
<tsuyoshi> jbu311: judging from that code you're not really thinking "functionally" yet.. once you do, ocaml is more enjoyable
<jbu311> ahha
<jbu311> yeah
<tsuyoshi> if you code like in c/python/java etc., ocaml can be very frustrating
<jbu311> I'm definitely trying to just map imperative code to functinoal
<ikatz> so this is a function to remove a vertex from the graph?
<jbu311> umm
<jbu311> yes
<jbu311> part of it
<jbu311> is to remove a vertex froma graph
<ikatz> ok cool, at least i'm reading it right :)
<jbu311> for each node m with an edge e from n to m do
<jbu311> remove edge e from the graph
<jbu311> if m has no other incoming edges then
<jbu311> insert m into Q
<jbu311> that's the pseudocode for this
<tsuyoshi> I learned lisp before ocaml so it was.. not painless but it's always seemed like a superior language than lisp to me
<jbu311> do people use ocaml in the industry?
<tsuyoshi> ocaml seems to be gaining popularity in finance, for some reason
<thermoplyae> i miss lisp's macros, but not enough to give up static typing and readable syntax
<ikatz> do you work for jane st capital yet? :)
piggybox_ has quit ["Leaving"]
<tsuyoshi> yeah.. the macros I miss... but it's hard to go back to dynamic typing
<ikatz> jbu311: first you fold the list of vertices
<tsuyoshi> I think I actually prefer lisp syntax
<ikatz> jbu311: and the function that you fold will find all the edges that go from that vertex to m
<jbu311> ikatz: i dont need to do anything with the list of vertices
<tsuyoshi> but it's not a big deal... I've a lot more experience with c than either lisp or ml
<ikatz> jbu311: and then you fold that list of edges...
<jbu311> actually is there a goto statement in ocaml?
<jbu311> :)
<ikatz> jbu311: with a function that removes them
<thermoplyae> lisp's syntax might have been more bearable with a reasonable editor (really with reasonable indentation)
<thermoplyae> but i used vim for my lisp stint, so it went pretty terribly :)
<tsuyoshi> the closest thing there is to a goto is raise
<ikatz> jbu311: and ten checks the other edges of m after that completes
<tsuyoshi> I did my own set of macros for lisp in nvi
<tsuyoshi> despite liking lisp I can't stand emacs
<ikatz> jbu311: "and then checks"
<jbu311> ikatz: hmm that sounds quite a bit above my level at the moment
<ikatz> jbu311: so, the "inner" fold will have to return whether m has incoming edges as well as the reduced list of edges
<ikatz> jbu311: which means the accumulator for the inner fold will be at least a 2-tuple
<jbu311> I think you've lost me way back
<jbu311> one sec
<ikatz> thats ok i think i screwed up n and m and overcomplicated this
<jbu311> I think I can do it if I can just access the "shrinking list" that's having stuff popped off of it while folding
<jbu311> being folded*
<ikatz> i think you want to build a list (in the accumulator) instead of accessing the old one
<jbu311> but once I find the edge let's - let's say I found it after looking through 1..a elements of the list - after that I still need to look through elements a...n to see if there's any other edges
<ikatz> well... you could do that check after you've processed all the edges, right?
<jbu311> no, i dont think so :(
<jbu311> ikatz: i'll figure it out I guess
<jbu311> thanks
<jbu311> I really dont have enough time or skill right now to try some advanced folding stuff
<jbu311> I guess I'm going to try to find a hack for it
p3l has joined #ocaml
dibblego has joined #ocaml
psykon_ has joined #ocaml
thermoplyae has quit ["daddy's in space"]
travisbrady has joined #ocaml
jbu311 has quit []
dibblego has quit [Client Quit]
p3l has left #ocaml []
psykon has quit [Connection timed out]
__suri_ has joined #ocaml
__suri has quit [Read error: 104 (Connection reset by peer)]
thermoplyae has joined #ocaml
a13x has joined #ocaml
<a13x> hi
<a13x> anybody alive?
sergez has joined #ocaml
<a13x> looks like no one is alive
<a13x> i had a great ocaml question
<thermoplyae> i'm alive, but not necessarily capable of answering
<a13x> oh i see, i guess ill ask anyway
<a13x> i have two modules
<a13x> then both have "open" to import each other
<a13x> i run into a recursive dependency problem with this
<a13x> how can i fix it? is there an equivalent ifndef as in C?
<thermoplyae> i don't think so, or at least i haven't found a way around it. might be possible with signatures or something, but i wouldn't know
<a13x> great, now i am totally stuck
<a13x> what are signatures?
<thermoplyae> types for modules, things you find in .mli files
<a13x> actually i am a newbe
<a13x> i may not have stated this right
<a13x> i have to .ml files
<a13x> both include (open) each other
<thermoplyae> no, i understood :)
<thermoplyae> elsewhere in the language circular dependencies are given special treatment
<thermoplyae> like let foo = bar and baz = nits
<thermoplyae> i'm not aware of such a thing for modules, so it may not exist, or it might work via signatures, which i haven't tested and have no real basis for believing other than that's sort of how C does it
<a13x> where can i read about signatures?
<thermoplyae> i imagine you would open the ocaml user manual and find them there :)
Yoric[DT] has joined #ocaml
<thermoplyae> here's someone actually knowledgeable
<Yoric[DT]> hi
<a13x> hi
<a13x> i had a question, if you don't mind
<a13x> i have two .ml files which "open" each other, how do i solve the circular dependency problem?
<a13x> are you there there?
<Yoric[DT]> Well, that's supposed to be impossible.
<Yoric[DT]> Modules may be recursive but not mutually recursive.
<Yoric[DT]> If you want mutual recursion, you should consider either parameterizing one module upon the other (i.e. functors) or turning your modules into classes.
<a13x> actually they are classes
<a13x> so i guess i would put them in the same file
<a13x> is that correct?
<Yoric[DT]> Indeed.
<a13x> darn, it would look bad
<a13x> oh well
<Yoric[DT]> How so ?
<Yoric[DT]> Otherwise, you can parameterize one class upon the other.
<Yoric[DT]> This will let you have each class in one module.
<a13x> i don't think parameterization is suitable in my case
travisbrady has quit []
<a13x> it would look bad because i have all classes in their own files except for this case
<Yoric[DT]> Well, the usual granularity for OCaml is larger than one class :)
<a13x> ok, i put all classes in one file, do i use "and" in between them
<thermoplyae> classes have structural polymorphism, it shouldn't be necessary
<a13x> there is a problem, it tells me "unbound type constructor" for the first class code
<Yoric[DT]> It actually depends on how you wrote your code.
<a13x> class bot brd (plr:player) =.....
<Yoric[DT]> But you shouldn't need the "and" unless you have explicitly used class names in your other classes.
<Yoric[DT]> Ok, you have explicitly used class names :)
<a13x> player
<Yoric[DT]> In this case, you do need "and".
<a13x> it tells me "syntax error"
<Yoric[DT]> Oh, and instead of plr:player, try plr:#player .
<Yoric[DT]> (this means "either player or any of its subclasses")
<Yoric[DT]> Can you pastebin the extract ?
<a13x> all of it?
<Yoric[DT]> Well, wherever you have your syntax error.
<a13x> ok, #player does not help, same error: unbound class player
<Yoric[DT]> Did you put "and" between the classes ?
<Yoric[DT]> class xxx = content_of_xxx and yyy = content_of_yyy and ... ?
<a13x> why end there?
<a13x> let me show you what i have
<Yoric[DT]> I don't have any syntax error with your file.
<a13x> right
<a13x> try putting and between those last two classes
<a13x> hell, this sucks
mfp has quit [Read error: 104 (Connection reset by peer)]
<a13x> this is my first ocaml program i have have spent more time writing code then i did debugging with c
<flux> that is indeed bad
<Yoric[DT]> Well, that's normal for a first program.
<a13x> not so normal when it comes to ml
<flux> a13x, you can declare a type for the player, which bot refers to
<a13x> i usually don't have such trouble with learning other languages
<a13x> what do you mean type?
ttamttam has joined #ocaml
<Yoric[DT]> a13x: were you familiar with ML languages already ?
<Yoric[DT]> (basically, you probably wrote "and class" instead of just "and")
<a13x> i had some hellish experience with SML
<a13x> i see
<a13x> but what to do with that module declaration?
<Yoric[DT]> module Bots ?
<a13x> yes
<Yoric[DT]> Why don't you use a hash-table instead of a map ?
<flux> a13x, another option: http://pastebin.com/d65d47437
<Yoric[DT]> Maps are designed for purely functional programming, but here you're essentially writing an imperative program.
<a13x> hash table is not suitable
<a13x> its a game that i am writing
<Yoric[DT]> I've seen that.
<Yoric[DT]> Now, what's the problem with hashtables ?
<Yoric[DT]> And what's the problem with Bots, by the way ?
<flux> actually I have a problem with that syntax, perhaps I'll fine tune it a bit still :)
<a13x> hash tables are for creating lists, right?
<a13x> i am not sure what you mean with your second question
<flux> http://pastebin.com/d3ede725c slightly fixed
<flux> hash tables are an imperative constuct for associating 'a with 'b
<flux> like Map, but they are imperative instead of functional
<flux> unlike Map(?) they can store multiple elements per key
<a13x> yes, i know
<flux> the last one shadowing earlier ones; but you don't need to use that
<flux> how are hash tables like lists?
<Yoric[DT]> I believe a13x means that hash tables may contain lists of associations.
<flux> they may, but you rarely use them that way
<a13x> this is how i understand hash tables: there are bins which contain your elements and you can easily calculate which bin to look in instead of iterating through a list
<Yoric[DT]> a13x: essentially, Hashtbl.replace is equivalent to what you do with add.
<flux> anyway, I would probably not construct a map or hash from bot to something, because if I were to add a function field to bot at some point it would stop working (functions aren't hashable or comparable). but that's not directly related to the problem at hand.
<Yoric[DT]> Hashtbl.iter is equivalent to your Bots.iter
<Yoric[DT]> And I don't know what your "choose" is.
<a13x> i will look into this
<a13x> choose is taking an element from the resulting set
<Yoric[DT]> a13x: another way of seeing hash tables is that they are like arrays, but without constraints on size or the type of the index.
<pango> flux: I'm not sure it would stop working, but worse case you could use a custom hash function with the functorized version of hash tables
<Yoric[DT]> i.e. arrays have limited size and the key is always an integer.
<a13x> yes, that is good way of saying it
<flux> choose is something Hashtbl doesn't have
* Yoric[DT] assumes Bots.choose is actually Bot.choose .
<flux> Map does infact have chooes, and it can be useful
<flux> for Hashtbl your solution would be a kludge like Hashtbl.iter (fun a b -> value:=Some (a, b); raise EarlyTerminate) h; not pretty!
<Yoric[DT]> flux: Maps has choose ?
<flux> yoric[dt], hm, actuall no! only Set has choose
<flux> interesting
<flux> so you need to use the same kludge for Map
<flux> infact I've used combinations of both Set and Make for similar reasons (min_elt etc)
mfp has joined #ocaml
<a13x> i am getting syntax errors using your solution
<Yoric[DT]> pastebin ?
<flux> the solution is missing virtual -keywords in from of "method"
<a13x> syntax error is at the first virtual method
<flux> ah, the syntax is different for methods when they are virtual
<flux> virtual method foo : int -> float -> unit
<flux> but I'm off to office, potentially resume within 30 min ->
thermoplyae has left #ocaml []
<a13x> still doesn't work: virtual method init : int -> int -> unit
<Yoric[DT]> Isnt'it "method virtual" instead of "virtual method" ?
* Yoric[DT] doesn't use objects too often.
<Yoric[DT]> Yep, what flux said + the "method virtual".
<Yoric[DT]> Do you use inheritance (or do you plan to) ?
<a13x> thanks, that worked
<Yoric[DT]> np
<a13x> i don't see where i would use inheritance
<a13x> now i get a nasty error
<a13x> Self type cannot escape its class
<Yoric[DT]> If you don't use inheritance, you'll probably be better off
<Yoric[DT]> with modules.
<Yoric[DT]> Okay, I can't replicate as I don't have all the necessary files.
<Yoric[DT]> Can you point me to the line ?
<a13x> it says line 72
<a13x> its talking about "self"?
<a13x> i have no idea why that would fail
<Yoric[DT]> mmmhhh....
<Yoric[DT]> You can try coercing self to board.
filp has joined #ocaml
<Yoric[DT]> Yep, replace "self" with "self :> board".
ygrek_ has joined #ocaml
<Yoric[DT]> Essentially, the problem is that "self" doesn't have a fixed type yet.
<Yoric[DT]> It can have type board or any subtype of board.
<a13x> oh, i see
<a13x> :> syntax error
<Yoric[DT]> ?
<a13x> oh
<Yoric[DT]> let bot = new bot (self :> board) plr
<a13x> (self :> board)
<a13x> seems to work
<Yoric[DT]> Yeah.
<Yoric[DT]> \o.
<a13x> great, thanks much
<Yoric[DT]> \o/
<Yoric[DT]> A pleasure.
<Yoric[DT]> But really, next time, unless you're sure you want inheritance, take a deeper look at modules, they're usually easier :)
* Yoric[DT] returns typing his OCaml tutorial.
Morphous has joined #ocaml
Morphous_ has quit [Read error: 110 (Connection timed out)]
seafood_ has quit []
<flux> a13x, at this point you might understand why oo in ocaml is object referred as an advanced subject :-)
<flux> (it's still great at times, though)
Tetsuo has joined #ocaml
seafood_ has joined #ocaml
ygrek_ has quit [Remote closed the connection]
<a13x> another question if you don't mind: how do i negate a boolean in ocaml?
<flux> not true;;
<xavierbot> - : bool = false
<a13x> i see, thanks (eclipse ocaml plugin didn't highlight not when i tried)
<bla> let not = function true -> false | false -> true
<bla> I guess it's just a simple function ;-)
<bla> But emacs highlights it.
<a13x> thanks
alexp has joined #ocaml
olleolleolle has joined #ocaml
SIGVTALRM has joined #ocaml
hkBst has joined #ocaml
mfp has quit [Read error: 110 (Connection timed out)]
g36130 has quit []
<munga> What is a good document where I can learn all about how to design abstract syntax trees ?
<munga> Something like: best practices to write a compiler in ocaml ...
<bla> There are some texts related to ocamlyacc and ocamllex which might cover your problem.
<Yoric[DT]> It doesn't really tell much about the AST.
<Yoric[DT]> I guess any book on compiler design should do.
olleolleolle has quit []
<alexp> munga, there is some great french lessons here ... http://pauillac.inria.fr/~remy/poly/compil/
<alexp> munga, I suppose that with an IP ending with pps.jussieu.fr, you read french :)
seafood_ has quit [Read error: 110 (Connection timed out)]
psykon_ is now known as psykon
pango has quit [Remote closed the connection]
pango has joined #ocaml
a13x has quit ["Leaving"]
jderque has joined #ocaml
psykon_ has joined #ocaml
Cosmos95 has joined #ocaml
Cosmos95 has quit [Client Quit]
<munga> alexp: I do. thanks !
psykon has quit [Read error: 110 (Connection timed out)]
olleolleolle has joined #ocaml
jderque has quit [Read error: 113 (No route to host)]
seafood_ has joined #ocaml
olegfink has quit [Read error: 113 (No route to host)]
seafood_ has quit [Client Quit]
jderque has joined #ocaml
seafood_ has joined #ocaml
olleolleolle_ has joined #ocaml
SIGVTALRM is now known as mfp
psykon_ is now known as psykon
psykon has left #ocaml []
olleolleolle has quit [Read error: 110 (Connection timed out)]
olleolleolle_ has left #ocaml []
jderque has quit [Read error: 113 (No route to host)]
robyonrails has joined #ocaml
cygnus_ has quit [Remote closed the connection]
seafood_ has quit []
RobertFischer has joined #ocaml
g36130 has joined #ocaml
<g36130> Hi! Using Ocaml 3.10. How to have backward compatibility with camlp4? Should I go back to 3.9 ?
<g36130> Or do you advise me to rewrite my code?
<flux> g36130, there's camlp5
<flux> I haven't tried it
<flux> but it's port of the old camlp for 3.10
<g36130> Ah, ok, thanks. But is the new camlp4 going to be the standard?
<flux> yes
g361301 has joined #ocaml
g36130 has quit [Read error: 110 (Connection timed out)]
g36130 has joined #ocaml
pango has quit [Remote closed the connection]
mwc has joined #ocaml
pango has joined #ocaml
mwc has quit ["Leaving"]
g361301 has quit [Read error: 110 (Connection timed out)]
filp has quit ["Bye"]
RobertFischer has left #ocaml []
jderque has joined #ocaml
thermoplyae has joined #ocaml
ttamttam has left #ocaml []
dramsay has joined #ocaml
jderque has quit [Read error: 113 (No route to host)]
postalchris has joined #ocaml
jbu311 has joined #ocaml
alexp has quit ["Leaving"]
<jbu311> hey guys, I thought all expressions in a "block" of code should be separated by a semicolon except the last one
<jbu311> is that not true?
<postalchris> where do you want to add/remove a semicolon that's troubling you?
<jbu311> postalchris: can I show u my code?
<jbu311> http://rafb.net/p/wvI4Df80.html lines 3-19 are getting executed all the time, and I believe its a problem of ocaml knowing where my if statement ends
yminsky has quit [Read error: 104 (Connection reset by peer)]
ttamttam has joined #ocaml
<thermoplyae> it's true, ; bind less tightly than if/then/else
<thermoplyae> you should wrap blocks of expressions in parentheses or in begin/end
<jbu311> I tried parentheses, but it said something about it not being a function
<jbu311> that the expression in parens wasn't a function and can't be applied
<jbu311> I'll try begin/end
<thermoplyae> the opening paren should be right after then and the closing should be right before the semicolon on the line q := (List.sort compare !q);
<postalchris> if-then takes exactly one expression, so if e1 then e2; e3 (as you have on lines 2-3) is parsed as (if e1 then e2); e3
<postalchris> You can do "if e1 then (e2; e3)" or "if e1 then begin e2; e3 end"
<jbu311> ok
<postalchris> I prefer using begin end in these situations, it's much easier to read
<jbu311> so how come sometimes when I have a single expression in an if statement, it sometimes requires that I use a semicolon after that expression
<jbu311> if it's just a single expression, I would guess that I wouldn't need the semicolon bc there's nothing to separate
<thermoplyae> you have to separate the expressions (if e1 then e2) from the next expression
<thermoplyae> expressions -> expression
<jbu311> ah
<jbu311> I tried begin/end and it gave me the same expression isn't a function error
<thermoplyae> did you put the end where i suggested?
<flux> and did you put a ; after end..
<thermoplyae> right
<jbu311> ah, the semicolon after end
<jbu311> great, thanks
<jbu311> its still hard to figure out where they need to be
<flux> begin and end are exactly the same as ()
<jbu311> ok
<flux> and this is valid expression: (5) + 3
<flux> but here you mean (5); 3
<flux> so you put a ; in there
<flux> begin 5 end + 3;;
<xavierbot> - : int = 8
<flux> begin 5 end; - 3;;
<xavierbot> Characters 7-8:
<xavierbot> Warning S: this expression should have type unit.
<xavierbot> begin 5 end; - 3;;
<xavierbot> ^
<xavierbot> - : int = -3
<kbidd> is equality in ocaml tested with = or ==?
<jbu311> uh
<jbu311> =
<jbu311> well
<jbu311> depends i guess?
<jbu311> what are you comparing
ygrek_ has joined #ocaml
<kbidd> int's
<jbu311> =
<jbu311> I found it very confusing that a lot of tutorials are written in top level so when I saw a lot of like for loops and stuff without a semicolon at the end it really screwed me up when I was writing non-top level
<Yoric[DT]> kbidd: =
<Yoric[DT]> == is something else
<Yoric[DT]> (actually, == is comparable to == but = is comparable to .equals )
<Yoric[DT]> (in terms of Java, that is)
<Yoric[DT]> Or, more generally : unless you have a good idea of what you're doing, = is the right operator for checking equality.
bongy has joined #ocaml
robyonrails has quit ["Leaving"]
bluestorm has joined #ocaml
<postalchris> Yoric: not sure I agree with that. Using (=) blindly can kill you on big data structures.
<postalchris> I'd say, unless you have a good idea of what you're doing, write a MYTYPE_equal function
<Yoric[DT]> Ok, probably depends on your level.
<Yoric[DT]> I teach my students to start with = .
<Yoric[DT]> If it turns out that the equality on their data structures is not structural equality (or that, God forbid, the data structures needing to be compared contain functions), then yeah, MYTYPE_equal.
<bluestorm> how does mytype_equal handle functions in general ?
thermoplyae has quit ["daddy's in space"]
<postalchris> my MYTYPE_equal ignores them, or doesn't put them there in the first place. ;-)
<postalchris> Comparing functions with (==) is OK, right?
<bluestorm> hm
<bluestorm> in the toplevel, it is
<bluestorm> although i'm not sure it's specified in the manual
<flux> comparing anything with == is ok
<Yoric[DT]> Not necessarily meaningful but ok.
jbu311 has quit ["ChatZilla 0.9.80 [Firefox 2.0.0.11/2007112718]"]
jlouis has quit ["leaving"]
xitrium has joined #ocaml
<xitrium> I have a question about http://rafb.net/p/Y4mQS559.html
<xitrium> I can't understand why it won't let me use my list of strings when it expects a list of one type...
<xitrium> any ideas?
<postalchris> (string list) isn't unifiable with ('a list list)
<xitrium> what does shouldn't fold just take 'a list?
<xitrium> err, minus "what does"
<postalchris> Yeah, I don't see where it's getting 'a list list from, but that's what it's got...
<xitrium> hmmm
<bluestorm> xitrium:
<bluestorm> let _ = List.fold_left addStuff (1, []) !lines in
<bluestorm> this line seems wrong
<bluestorm> what's the type of "prevVal" in your addStuff function ?
<bluestorm> your giving an empty list here
<postalchris> [] should be a string
<bluestorm> shouldn't it be a string ("" ?) ?
jstanley has joined #ocaml
<xitrium> ahh, yeah
<xitrium> let me try that, thanks
<bluestorm> hm
<bluestorm> besides
<bluestorm> your "mod 2" stuff is quite messy
<bluestorm> i liked the "two read at a time" method more
<xitrium> two read at a time?
<bluestorm> hm
<bluestorm> you could use lines as a (string * string) list ref
<jstanley> Hey folks. I'm trying to compile some ocaml code + some C wrappers for the ocaml code into a shared library, but I'm not able to get the shared lib to link. Any ideas?
<xitrium> ah
<bluestorm> then you wouldn't need all that "mod 2" recursion
<xitrium> true
<jstanley> I'm missing stuff like _caml_code_area_end and _caml_atom_table that libasmrun refers to.
<bluestorm> hm
<bluestorm> let _ = List.fold_left addStuff (1, []) !lines in
<bluestorm> is equivalent to
<bluestorm> List.fold_left addStuff (1, []) !line;
<bluestorm> the second one being clearer imho
<xitrium> that's true
<bluestorm> (it clearly states you're using a side effect)
<bluestorm> xitrium: btw, if you like the "let ... = .. in" idiom
<xitrium> I wish I was better at not using side effects, but for the moment I don't have a good grip on it :(
<bluestorm> i'd advise you to try "let () = ... in"
<xitrium> what's that do?
<bluestorm> at least it shows that the expected result is unit
<xitrium> ah
<bluestorm> (and type-checks)
<xitrium> nice
<pango> yes but in this case it will fail
<bluestorm> hmm
<bluestorm> right :D
<pango> I don't think the result will be unit
<bluestorm> actually, i was thinking of the "Hashtbl.add" line
<bluestorm> the List.fold_left line doesn't return unit
<pango> yes, that one will work
<bluestorm> so if you want to use "let () = .." or "...;", you should use "ignore"
<bluestorm> ignore (List.fold_left ...);
<xitrium> haha
<xitrium> ok, thanks everyone
<jstanley> I'm using gcc -c wrapper.c -I /usr/local/lib/ocaml ; ocamlopt -output-obj -o simple.o simple.ml ; gcc -dynamiclib -o test.dylib -L/usr/local/lib/ocaml -lasmrun wrapper.o simple.o ... does anything look wrong with that?
<xitrium> I'm switching to the tuple read-in now
<pango> xitrium: what tasks' type is supposed to be?
<bluestorm> xitrium: beware of the evaluation order
<bluestorm> lines := (read_line (), read_line ()) :: !lines; is not likely to do what you want
<pango> whether it's (string, string) Hashtbl.t or (string, string list) Hashtbl.t, the code doesn't type correctly
<pango> (but breaks in different places)
<xitrium> tasks I want to be (string, string)
<xitrium> ah, that's what I was goign to do for the double line reading thing
<pango> so you can't start by using [] as a value to insert
<xitrium> What should I do instead?
<xitrium> pango: okay, fixing
<pango> I don't know, I'm not sure what you're trying to do... but as-is, the code is inconsistent
<xitrium> bluestorm: how would you recommend me reading in a tuple of two lines?
<bluestorm> let first = read_line () in
<bluestorm> let second = read_line () in
<bluestorm> ..
<pango> next you have a problem with Hashtbl.iter, that takes a key -> value -> unit function as parameter
<bluestorm> or "key_line, value_line" might sound better in your case
<bluestorm> xitrium: do you need to use a list ref ?
<bluestorm> you could insert into the Hashtable directly
<jstanley> When I try to use ocamlmklib with some code generated from ocamlopt, I get: ld: absolute addressing (perhaps -mdynamic-no-pic) used in _caml_startup__code_begin from simple.o not allowed in slidable image
<xitrium> bluestorm: that is a very good point... haha
<xitrium> pango: is there a way to print a hashtable? or do I just make my own function and use it there?
<bluestorm> i think you have to use your own function
<xitrium> ah
<pango> xitrium: an anonymous function will do
<xitrium> sweet
<xitrium> i'll do that
<xitrium> thanks both of you :D
bongy has quit ["Leaving"]
<xitrium> sweet, I got it working. Now on to the hard part :P
ttamttam has left #ocaml []
ttamttam has joined #ocaml
ttamtta1 has joined #ocaml
ttamttam has quit [Client Quit]
ttamtta1 has left #ocaml []
ttamttam has joined #ocaml
ReachingFarr has joined #ocaml
Linktim has joined #ocaml
Linktim has left #ocaml []
<jstanley> Does anyone know how to build a shared library that includes compiled ocaml code? I'm not having any luck at all :( ocamlmklib isn't what I want, either.
<xitrium> I have no idea, sorry
<g36130> Hi! What's the difference between fun and function?
<xitrium> fun is declaring an anonymous function, i think
<Yoric[DT]> One accepts several arguments, the other doesn't.
* Yoric[DT] doesn't remember which one is which.
<Yoric[DT]> jstanley: that's the kind of question you should ask on the mailing-list.
<postalchris> function takes only one argument, which can be pattern-matched
<postalchris> fun takes an arbitrary number of arguments, which can't (except to deconstruct tuples)
<mfp> jstanley: that only works on some platforms (issues with non-PIC code)
<mfp> do you happen to be using x86 + Linux, FreeBSD or Win32? (no pb on those)
<Yoric[DT]> s/should/could/
<mfp> jstanley: essentially, ocamlopt -c foo.ml; ... ocamlopt -output-obj -o whatever.o somelib.cmxa foo.cmx bar.cmx foo.o bar.o; gcc -shared -o mylib.so extra.o objects.o whatever.o /path/to/libasmrun.a /path/to/libnums.a ...
<mfp> allowing you to include objects generated by GCC or some other compiler
<mfp> you need to register the OCaml values and get them from C with caml_named_value, etc.
<jstanley> mfp: mac os x atm, and yeah, i'm getting errors pertaining to PIC
<jstanley> mfp: yeah, the bridge between C and ocaml works just fine if i statically compile into an app
<mfp> ouch OSX = trouble
<mfp> might work with CVS HEAD / natdynlink branch
<jstanley> mfp: damn.
<mfp> but I never got it to work with 3.9.y/3.10.x on OSX
<jstanley> mfp: so i take it the ocamlopt code generator just doesn't generate pos indep code for some platforms (incl os x)?
<mfp> AFAIK 3.10 only generate PIC code in a few platforms (or maybe only x64...)
<mfp> x86 linux/FreeBSD's linker can handle non-PIC objects in a .so, but neither x86-64 linux nor OSX can
<Yoric[DT]> Just for my culture: PIC = relocatable ?
<jstanley> Yoric[DT]: Yup
<mfp> yep, pos indep
<Yoric[DT]> thanks
<jstanley> Yoric[DT]: pic = position independent code
<jstanley> Man, this is pretty frustrating. I was hoping I could wrap up a nice ocaml lib and call it from C via a dylib.
* Yoric[DT] remember producing pic stuff with gcc as a student but not *why* he did that.
<Yoric[DT]> s/remember/remembers/
<jstanley> Yoric[DT]: Yeah the code gets stored with address references that are relative instead of absolute, so e.g. it can be stored in a shared code cache
<Yoric[DT]> Yeah, I pretty much assumed it was something like this.
<mfp> as I said, might work with natdynlink/HEAD, since it must be doing PIC generation for the .cmxs dynamic loading
<mfp> haven't tried myself yet, though
<jstanley> mfp: i'm pretty new to ocaml, though -- where can i find out how to access the cvs head you're talking about?
<jstanley> and the libasmrun/libnums/etc are going to have to be compiled with PIC as well, am i correct?
<mfp> the runtime will also need -fPIC I think
<jstanley> *nod*
<mfp> ah you can also use http://repo.or.cz/r/ocaml.git/
<mfp> master branch, I guess
<mfp> (should be much faster than CVS)
<jstanley> so you're suggesting that i (a) compile from latest ocaml head, (b) do some biology experiments to see if I can get PIC code generating on this platform. Is that right?
<mfp> that's the only option left for OSX
<jstanley> okay, that's cool -- i was just making sure I was understanding your suggestion ;P
<jstanley> thanks.
<mfp> but I don't know if it'll work :-|
<jstanley> yah, i'm with ya
<jstanley> i just haven't built ocaml yet...hopefully i can get it to build happily.
<mfp> now, it seems it should... Alain Frisch said he had dynamic loading working on OSX, and those .cmxs must be using PIC code
<jstanley> *nod*
<jstanley> Should I expect to see a new command line option in the updated ocamlopt to specify that?
<jstanley> Or do you think it'd be on by default?
<mfp> -fPIC maybe?
* jstanley prays.
<jstanley> k cool
<mfp> I know x86-64 does -fPIC by default, don't know if there's anything new for the native code thingy
<jstanley> alrighty.
<mfp> I'd love to know if it actually works... if you run into problems, a quick post to the ML might get you a response from Alain Frisch
<jstanley> Sounds good, I'll definately do that if I run into a dead end.
<jstanley> Thanks for your help, mfp.
<mfp> np
<mfp> looking forward to your success report ;)
<mfp> the ML is more lively as of late and I'm sure more ppl will be interested in any step forward
<Yoric[DT]> The DevDay sure did bring some life to the community.
<jstanley> mfp: make opt is failing under mac os x :(
pattern has joined #ocaml
jlouis has joined #ocaml
ttamttam has left #ocaml []
thermoplyae has joined #ocaml
ReachingFarr has quit ["Leaving."]
xitrium has quit ["JWIRC applet"]
li` has joined #ocaml
ygrek_ has quit [Remote closed the connection]
Cosmos95 has joined #ocaml
Tetsuo has quit ["Leaving"]
li` has left #ocaml []
<jstanley> Is Caml-list (at yquem.inria.fr) the general ocaml mailing list?
<bluestorm> i know of no other one
<Yoric[DT]> I know of two others (ocaml-beginners and ocaml-developers), but that's the one.
<jstanley> thanks.
<jstanley> Anyone had experience building a shared lib with mixed ocaml and C code using the -shared and -dlcode options to ocamlopt available via the merged natdynlink branch?
<mfp> got make opt to work?
<jstanley> Yeah -- I cvs co'd right from the main CVS head instead of the branch.
<jstanley> Since I read a page that said it'd been merged.
<mfp> yep
<mfp> (but not in the git repos though :-S )
<jstanley> hehe yeah
hkBst has quit ["Konversation terminated!"]
<jstanley> But now I'm looking for confirmation that I'm doing the right thing to test it out ;) Mainly gcc -fPIC -c wrapper.o ; ocamlopt -shared -o test simple.ml wrapper.o
<jstanley> but my guess is that it's not working for mac os x, given that ocamlopt is invoking ld -bundle and not gcc -dynamiclib for building the library.
ita has joined #ocaml
<jstanley> and when i attempt to link manually with the right options, it's still telling me that simple.o isn't PIC
<jstanley> to wit: "ld: absolute addressing (perhaps -mdynamic-no-pic) used in _camlSimple__f_58 from simple.o not allowed in slidable image"
<jstanley> =(
<mfp> there's also -dlcode IIRC
<jstanley> yeah, so i tried making the .cmx from simple.ml
<jstanley> same error :(
<jstanley> I'll compose something for the mailing list.
dibblego has joined #ocaml
StoneNote has joined #ocaml
dramsay has quit ["This computer has gone to sleep"]
ita_ has joined #ocaml
<Yoric[DT]> Good night everyone.
Yoric[DT] has quit ["Ex-Chat"]
thelema has joined #ocaml
ita has quit [Connection timed out]
thelema is now known as thelema|away
ita_ has quit ["Hasta luego!"]
rieux has joined #ocaml
<rieux> hi. i'm wondering if someone could help me with a camlp4 (linking, i think) problem.
aheller has joined #ocaml
<rieux> i'm trying to make a standalone program that relies on camlp4 for parsing and printing some parts of a dsl (embedded bits of ocaml), so it needs to call into camlp4 for parsing and printing. i've gotten what i think is a minimal test program, which dies when I run it with a message that "entry [expr] is empty", which indicates to me that I'm not loading a parser properly:
<rieux> open Camlp4.PreCast
<rieux> let ast = Gram.parse Syntax.expr (Loc.mk "-") (Stream.of_channel stdin) in
<rieux> let _loc = Ast.loc_of_expr ast in
<rieux> Syntax.print_implem <:str_item< let foo = $ast$ >>
<rieux> (I'm linking all of camlp4lib.cma Camlp4Parsers/Camlp4OCamlRevisedParser.cmo Camlp4Parsers/Camlp4OCamlParser.cmo Camlp4Printers/Camlp4OCamlPrinter.cmo in order before my code)
<rieux> (oh, and i had this working fine in 3.09, but i'm trying to migrate to 3.10.)
<bluestorm> hm
<bluestorm> rieux: you could use camlp4
<bluestorm> ...
<bluestorm> camlp5
<bluestorm> as a temporary solution
<bluestorm> (... or permanent one)
<rieux> yeah, i was thinking about that, but i need to use private row types, and afaik, camlp5's ast doesn't support them.
<rieux> though if it does now, i should give it another shot.
<rieux> thanks for the idea, though -- if i can't get this working, i might see if i can do without the private row types.
mwc has joined #ocaml
<bluestorm> hm rieux