mfp changed the topic of #ocaml to: Discussions about the OCaml programming language | http://caml.inria.fr/ | OCaml 3.11.2 released | Inscription for OCaml Meeting 2010 is opened http://wiki.cocan.org/events/europe/ocamlmeetingparis2010
bluestorm has quit [Quit: Leaving]
_unK has quit [Quit: Konversation terminated!]
_unK has joined #ocaml
thrasibule has joined #ocaml
joewilliams is now known as joewilliams_away
thrasibule_ has joined #ocaml
thrasibule has quit [Ping timeout: 276 seconds]
Amorphous has quit [Ping timeout: 258 seconds]
smimram has quit [Read error: Operation timed out]
tmaedaZ is now known as tmaeda
pimmhogeling has quit [Ping timeout: 265 seconds]
smimram has joined #ocaml
slash_ has quit [Quit: Lost terminal]
Amorphous has joined #ocaml
bzzbzz has quit [Quit: leaving]
drk-sd has quit [Quit: foo]
ikaros has quit [Quit: Leave the magic to Houdini]
smimram has quit [Ping timeout: 268 seconds]
smimram has joined #ocaml
derdon has quit [Quit: derdon]
tmaeda is now known as tmaedaZ
<sc30317> thelema, are you there?
<sc30317> I want to do a recursive function for a given number of iterations
<sc30317> anyone know how to do that?
<Chile> count the iterations with a parameter, start returning when you hit the number you want
<sc30317> Chile, what parameter?
<Chile> a new parameter you add to your recursive function
<Chile> assuming the depth is otherwise arbitrary
<sc30317> ok
joewilliams_away is now known as joewilliams
<sc30317> Chile, can I ask you another question?
<sc30317> lets say you have 2 vectors of the same size
<sc30317> lets use [a;b;c;d] and [d;e;f;g]
<sc30317> I am using the List.for_all2 function to compare the two as shown
<sc30317> let compare_vc_current_class input1 input2 = List.for_all2 (fun x y -> x > 0.0 && y > 0.0 || x < 0.0 && y < 0.0) input1 input2
<sc30317> is there a way to show which rows are not both the same sign?
<sc30317> like say if a and d were not the same, say row 1 is not the same
<sc30317> so on and so forth down the line
<sc30317> Anyone can answer if they are on
<sc30317> Anyone alive?
zhijie has quit [Read error: Connection reset by peer]
zhijie has joined #ocaml
zhijie has quit [Read error: Connection reset by peer]
zhijie has joined #ocaml
Tianon has joined #ocaml
Tianon has quit [Changing host]
Tianon has joined #ocaml
zhijie has quit [Read error: Connection reset by peer]
zhijie has joined #ocaml
_unK has quit [Remote host closed the connection]
yakischloba1 has joined #ocaml
zhijie has quit [Read error: Connection reset by peer]
tmaedaZ is now known as tmaeda
yakischloba has quit [Ping timeout: 276 seconds]
zhijie has joined #ocaml
<sc30317> anyone on here that can answer questions?
zhijie has quit [Read error: Connection reset by peer]
zhijie has joined #ocaml
zhijie has quit [Read error: Connection reset by peer]
zhijie has joined #ocaml
<sc30317> mrvn, you there?
maskd has quit [Quit: leaving]
zhijie has quit [Read error: Connection reset by peer]
zhijie has joined #ocaml
zhijie has quit [Read error: Connection reset by peer]
zhijie has joined #ocaml
<sc30317> Chile, are you still here?
<sc30317> anyone here?
enthymeme has joined #ocaml
tmaeda is now known as tmaedaZ
<sc30317> anyone know recursion?
zhijie has quit [Read error: Connection reset by peer]
zhijie has joined #ocaml
jonafan_ has joined #ocaml
zhijie has quit [Read error: Connection reset by peer]
jonafan has quit [Ping timeout: 248 seconds]
zhijie has joined #ocaml
zhijie has quit [Read error: Connection reset by peer]
zhijie has joined #ocaml
zhijie has quit [Read error: Connection reset by peer]
smimram has quit [Ping timeout: 248 seconds]
zhijie has joined #ocaml
zhijie has quit [Read error: Connection reset by peer]
<sc30317> echo?
zhijie has joined #ocaml
zhijie has quit [Read error: Connection reset by peer]
joewilliams is now known as joewilliams_away
zhijie has joined #ocaml
zhijie has quit [Read error: Connection reset by peer]
zhijie has joined #ocaml
zhijie has quit [Read error: Connection reset by peer]
zhijie has joined #ocaml
zhijie has quit [Read error: Connection reset by peer]
smimram has joined #ocaml
zhijie has joined #ocaml
zhijie has quit [Read error: Connection reset by peer]
dark has joined #ocaml
zhijie has joined #ocaml
<sc30317> can any of you answer a question on recursion?
zhijie has quit [Read error: Connection reset by peer]
zhijie has joined #ocaml
zhijie has quit [Read error: Connection reset by peer]
zhijie has joined #ocaml
zhijie has quit [Read error: Connection reset by peer]
zhijie has joined #ocaml
zhijie has quit [Read error: Connection reset by peer]
zhijie has joined #ocaml
zhijie has quit [Read error: Connection reset by peer]
zhijie1 has joined #ocaml
zhijie1 has quit [Read error: Connection reset by peer]
zhijie1 has joined #ocaml
zhijie1 has quit [Read error: Connection reset by peer]
thrasibule_ has quit [Ping timeout: 260 seconds]
zhijie1 has joined #ocaml
zhijie1 has quit [Read error: Connection reset by peer]
<dark> sc30317, ask it
<sc30317> thanks dark
<sc30317> dark,
<sc30317> I have this function
<sc30317> let compare a list1 list2 =
<sc30317> let rec c a new_vector =
<sc30317> if a <= 0 then new_vector
<sc30317> else if (List.nth list1 a > 0.0 && List.nth list2 a > 0.0) ||
<sc30317> (List.nth list1 a < 0.0 && List.nth list2 a < 0.0) then f (a - 1)
<sc30317> (list1::new_vector) in c a []
<sc30317> else f (a - 1) (0.0::new_vector) in c a []
<sc30317> All I want it to do is compare list1 and list2. if they are both positive
<sc30317> or both negative, put a 0.0 in the new_vector. if they are not both
<sc30317> positive or negative, put list1 in the new_vector.
<sc30317> Why won't this work?
<dark> sc30317, (do you know pastebins?)
<sc30317> dark, yes, I can pastebin that for you h/o
<dark> hm
<dark> List.nth? this is not the "ocaml way" of doing anything
<dark> how can you guarantee that the list actually has a nth element?
<sc30317> im not sure
<sc30317> I guess you cant
<dark> also, what is a "vector"? it's your name for "list"?
<sc30317> yes
<sc30317> do you understand what I am attempting to do?
<dark> hmmm not really, :) what is what you are trying to accomplish, *actually*?
<sc30317> ok
<sc30317> I have list1 and list2
<sc30317> they are both lists
<sc30317> I would like to go through the lists
<dark> okay, lists of floats
<sc30317> correct
<sc30317> if list1 and list2 are both positive at a position
<sc30317> or negative
<sc30317> put the element of list 1 into a new list
<dark> hmm
<sc30317> if not, put a 0.0 into that list
<dark> the result is a list of "signals"
<sc30317> I guess you could say that
<dark> for ex, [1.0; 2.0; -1.0] and [1.0; -2.0; -1.0] will give [+; -; +]
zhijie1 has joined #ocaml
<dark> or [true; false; true]
<dark> but you choose [1.0; 0.0; 1.0]
<dark> right?
<sc30317> yes, that is what I want it to return
<sc30317> [1.0; 0.0; -1.0]
<dark> ah
<dark> 3 values?
<dark> one for "both positive"
<dark> other "both negative"
<dark> other "different signal"
<sc30317> yea
<sc30317> but the values are just coming from list 1
<sc30317> so like say you had
<dark> okay, then i'm certain: you are doing it the wrong way ^_^' you are from a imperative (C, C++..) background, right?
<sc30317> [1;2;3] [4; -5; 6]
<sc30317> that would return [1;0;3]
<sc30317> yes, I am from a C background :D
zhijie1 has quit [Read error: Connection reset by peer]
<dark> hmmm what i can't understand is that a. what it is for?
<dark> it's a dummy counter, like... the for (int i ..?
<sc30317> yea
<dark> hahahahaha!!!!!! ^^'
<sc30317> haha
<sc30317> you can def. see my C programming coming into play, huh?
<dark> :) wait a sec
<sc30317> ok
zhijie1 has joined #ocaml
sc30317 has left #ocaml []
sc30317 has joined #ocaml
<sc30317> dark, sorry
<dark> i don't have an ocaml interpreter here, is failwith a function?
<dark> failwith "something", try this
<sc30317> yes thats it
zhijie1 has quit [Read error: Connection reset by peer]
<sc30317> try what?
<dark> do you require it to be tail recursive?
<sc30317> sure
<sc30317> if you want/need an ocaml interpreter, I can let you ssh to my box
<dark> no, i don't need, just test if this works: http://pastebin.com/78yCBCaU (not tail recursive)
<dark> this kind of function has a problem: the two lists has to have the same size
<sc30317> they will be
<sc30317> for sure
<dark> whenever you need to process lists, you have two options: a) bare recursion, b) fold and friends (map, ..)
<dark> you can make recursion with two or more lists, just like that
zhijie1 has joined #ocaml
zhijie1 has quit [Read error: Connection reset by peer]
<sc30317> dark, that just returns a 0 or a 1
<dark> when you build this as a recursion, you see that there is two error cases
<dark> hm
<sc30317> I wanted it to return the value of the first list
<sc30317> your function:
<sc30317> # my_compare [1.0;2.0;3.0] [-1.0;5.0;4.0];;
<sc30317> - : float list = [0.; 1.; 1.]
<dark> hmmm... it is returning what i thought it was going to return, o.o
<sc30317> where I would want it to be [0.;2.;3]
zhijie1 has joined #ocaml
<dark> what it should return, in this case?..
<dark> ahn, o.o
<sc30317> oh
zhijie1 has quit [Read error: Connection reset by peer]
<sc30317> I could change that -1 to a?
<dark> then change the signal_of_floats parts
<dark> yes.. o.o
<dark> do you know how to turn this into a tail-recursive version? (do you know the difference?)
<sc30317> no (to both accounts)
<dark> the method i know is to build a function that will hold an accumulator
<dark> hmm did you ever heard people saying 'don't do this recursive, because you can fill up the stack'?
<sc30317> yes
<sc30317> I have done that before :D
<dark> as you already noticed, this algorithm has an imperative version.. with for, that will not use a stack
<dark> ocaml will turn the recursion to a loop automatically, whenever it encounter this pattern.. but only for certain kind of functions
<sc30317> ok
<sc30317> so there is no reason to use the imperitive version?
<dark> in fact, whenever the return value of a function is a tail call (i.e., just a call to another function), it does not need to do a call + return.. it can do just a jump
zhijie1 has joined #ocaml
<dark> in ocaml, no, the code generated is the same -- but only if you write your recursive functions using only tail calls
<dark> i.e., your functions must be tail-recursive
<sc30317> ok
<sc30317> why do you say tail-recursive?
<sc30317> is there another "head" recursion?
<dark> hmm i'll write a tail-recursive factorial for you
zhijie1 has quit [Read error: Connection reset by peer]
<dark> let fat n = let rec fat_loop acc c = if c = 0 then acc else fat_loop (acc * c) (c - 1) in fat_loop 1 n
<dark> do you know the "normal" version, right? let fat n = if n = 0 then 1 else n*(fat (n-1))
<dark> let rec fat
<sc30317> yes
<sc30317> I was actually looking at that earlier
<sc30317> let rec fact x = if x=0 then 1
<sc30317> else x*fact(x-1);;
<dark> notice that in the recursion case, the result of fat_loop is directly the result of a call of fat_loop itself
<dark> in the usual factorial, you need to store the intermediate values of fact x
<dark> because you need to * them after calculating all values
<dark> in the tail recursive version, you don't o.o
<sc30317> ooooooh
<sc30317> gotcha
<sc30317> I understand now
<dark> if you don't know exactly that you need tail recursive functions, you usually don't
<sc30317> gotcha
<dark> sc30317, http://pastebin.com/vF3zaY7Z tail recursive
zhijie has joined #ocaml
<sc30317> ok dark
zhijie has quit [Read error: Connection reset by peer]
<sc30317> that is way cool!
<dark> it looks like you learned it fast (i didn't...), but just to clarify, in the fact example, the tail recursive factorial will be translated into a loop, that will update two variables: an accumulator, and an index. it will be just like for (int i = n; i >0; i--) acc *= i;
<dark> yes it is :)
<sc30317> cool man
<sc30317> I have a couple more questions if you dont mind
<dark> i don't mind ^^
<sc30317> ok, how do I get ocaml to not think this is a comment?
<dark> 'this' being..?
<sc30317> let vector_mult input1 input2 = List.map2 (*.) input1 input2
<dark> ( *. )
<sc30317> oh
<sc30317> space?
<dark> (* .. *) is a comment, ( * .. * ) isn't
<sc30317> gotcha
<sc30317> ok
<sc30317> I want to do a weird mult
zhijie has joined #ocaml
<sc30317> h/o let me do a pastebin of it
<dark> hm
<dark> ps: you can implement that map2 using the same technique i used to do my_compare
<sc30317> yea, now that you showed me that I realize the my_compare could work a myriad of different ways
<dark> all of this is just a single operation: fold [fold can be used to build map, and this my_compare]. most functional code will be written using folds, maps, etc instead of bare recursions
<dark> fold is called reduce in ruby
<sc30317> this is what I want to do
<sc30317> I have part a and part b
<sc30317> and I want to make the new matrix
zhijie has quit [Read error: Connection reset by peer]
<dark> hmmm o.o
<dark> you want a matrix multiplication?
<sc30317> yes; I have used that before
<sc30317> no, a matrix addition
zhijie has joined #ocaml
<dark> but one is 4x3 and the other is 4x1
<sc30317> yes
zhijie has quit [Read error: Connection reset by peer]
<sc30317> but you add down the columns
<sc30317> see the first row in the new matrix
<dark> you want to add the 4x3 to the 4x1 repeated in all columns?
<sc30317> is a1 + b4 + c7 + d10
<dark> this seems like a matrix multiplication o.o
<sc30317> it isn't?
<sc30317> maybe it is?
<dark> can't you say what you are trying to do? :P
<dark> it looks like linear algebra
<sc30317> it is
<sc30317> thats the thing; im not allowed to use the array modules
<dark> it's a assignment?
<dark> an
<sc30317> no
<sc30317> boss said so
<dark> boss..? wtf, he actually understand anything at all about ocaml?
<sc30317> not really; I think he just wants me to learn the constructs of the list module?
<dark> is this 'real world' job, or in academia?
<sc30317> real world
<sc30317> :D
zhijie has joined #ocaml
<dark> omg
<sc30317> yea tell me about it
zhijie has quit [Read error: Connection reset by peer]
<sc30317> systems programming in ocaml
<sc30317> wtf
<dark> but where?
<dark> i have saw some of this
<sc30317> where what?
<dark> but never saw matrix multiplication with lists
<dark> where are you?
<sc30317> south carolina
zhijie has joined #ocaml
<sc30317> very small company
zhijie has quit [Read error: Connection reset by peer]
<dark> interesting o.o
<dark> but okay: you need to be somewhat clever if you want to avoid writing recursions by hand and still have a correct program (ps: forget the List.nth .. lists are not arrays)
<dark> if you are learning ocaml, i suggest you to simply accept that all your list functions will be written in a recursive style
<dark> no matter what they do
zhijie has joined #ocaml
<sc30317> ok
zhijie has quit [Read error: Connection reset by peer]
<dark> now you need to think if you want to recourse on the first list, on the second, or both, but i suggest recour..sing?(this word doesn't seems to exist) on the first
<sc30317> ok
<dark> but the result of each row will be something like multiply a list
<dark> right?
<dark> a is a number, list er a list
<dark> then multiply needs to be another recursive function
<dark> :P...
<sc30317> a is a number
<sc30317> a float
<dark> but you can write this easily with fold
<dark> List_fold_left (+.) 0.0 list
<dark> will sum all elements of a list
<dark> 0.0 is the base case (for the empty list)
<sc30317> ok
<dark> +. is really (fun a b -> a +. b)
<sc30317> ok
<dark> i.e you can use fold for building an arbitrary data structure from iterating the elements of a list
<sc30317> sounds good
ulfdoz has joined #ocaml
<dark> the function that is the first parameter of a fold receives two parameters a and b: a is the accumulator, b is the top of the list
<dark> and returns a new accumulator (that may be returned when the list is over, or will be passed as the acc of the next function call)
<dark> you can implement this function if you are not confident it works and is tail recursive
<sc30317> ok
<dark> in fact you can use fold for building the entire function too
<sc30317> cool!
<dark> you want to build a "data structure" from a "list"
<sc30317> alright....
<dark> (ps: there is usually fold for every iterable data structure in ocaml, like sets)
<sc30317> dark, where are you located?
<dark> i'm at natal, brazil
<sc30317> oh cool!
<sc30317> talk about far away!
<dark> hehe :)
<dark> there is a professor here that is from france, he teaches ocaml for freshmen here
<sc30317> cool
<sc30317> are you a uni student?
<dark> people hate this, but i enjoy ocaml (and functional programming in general)
<dark> yes ^^
<sc30317> thats cool
<dark> i found surprising a small company is working with ocaml, and apparently misusing it (or maybe not?)
<dark> there are some (quite small...) companies here, but they will work with java...
<dark> or c++, or microsoft languages
<mrvn> dark: His boss is just verry bad at teaching ocaml.
<sc30317> hey mrvn
<sc30317> whats up?
<mrvn> breakfast
<sc30317> hah
<sc30317> where are you?
<mrvn> germany
<sc30317> cool
<dark> sc30317, you need to first program a "dot product"
<sc30317> I may
<sc30317> h/o let me reference that
<mrvn> Did you start from scratch again?
<sc30317> mrvn, no
* dark is reading http://en.wikipedia.org/wiki/Matrix_multiplication - i stated that the matrix multiplication can be written just with fold, but now this seems challenging :P
<sc30317> dark, a dot product is exactly what I need
<dark> sc30317, but now you know that technique for writing recursive functions that will receive two lists, right?
<sc30317> correct
<sc30317> I think :D
zhijie has joined #ocaml
<mrvn> dark: transpose, map, ... are all just folds
zhijie has quit [Read error: Connection reset by peer]
<dark> yes, i was stating that too. and hmm i think i know how to build map with fold, but what is 'transpose'?
<mrvn> changing from row to column form
smimram has quit [Read error: Operation timed out]
<dark> sc30317, the dot product recursion is something like is a::r, b::s -> (a * b) + (dot_product r s).. or a::r, b::s -> loop (a * b) r s
<dark> hm
<sc30317> ok
zhijie has joined #ocaml
<dark> yes, it make things easier mrvn
<dark> hmm loop (acc + a * b) r s
<sc30317> that has a syntax error
<dark> where?
<mrvn> +. *.
<dark> yes, sorry =)
<sc30317> no prob
<sc30317> nope, still one :(
<dark> paste your code in the pastebin
zhijie has quit [Read error: Connection reset by peer]
zhijie has joined #ocaml
<dark> no err i meant by modifying the other function, my_something
<sc30317> oh ok
<dark> maybe let rec dotproduct a b = match a, b with [], [] -> 0. | _::_, [] | [], _::_ -> failwith "diff size" | a::r, b::s -> (a * b) + (dotproduct r s)
<dark> not tail recursive
<mrvn> let dotproduct v1 v2 = List.fold_left (fun x (a,b) -> x +. a *. b) 0.0 (List.combine v1 v2);;
<dark> ^^ nice
<dark> but i'm not sure
<sc30317> alright cool
<mrvn> # let dotproduct = List.fold_left2 (fun x a b -> x +. a *. b) 0.0;;
<mrvn> val dotproduct : float list -> float list -> float = <fun>
<dark> fold_left2? hmm
<sc30317> nice MrHeavy
<dark> really nice this fold_left2 version. a plus is that it is automatically tail recursive
<mrvn> Hardly matters for 3D vectors
enthymeme has quit [Quit: rcirc on GNU Emacs 23.1.1]
aja has joined #ocaml
smimram has joined #ocaml
aja has quit [Remote host closed the connection]
<sc30317> dark, why does that my_compare not work like this?
<sc30317> # my_compare [-1.0;-1.0;-1.0;1.0] [-0.078705 -0.097369 -0.198243 -0.216906];;
<sc30317> Error: This expression has type float but an expression was expected of type
<sc30317> int
oc13 has joined #ocaml
<dark> maybe you have a + in place of +. etc
<sc30317> maybe
<dark> and ahh
<dark> you need ;
<dark> [-0.078705; -0.097369; -0.198243; -0.216906]
<sc30317> gotcha
<sc30317> what a dummy
<sc30317> when I do that though, I get
<sc30317> # my_compare[-1.0;-1.0;-1.0;1.0] [-0.078705; -0.097369; -0.198243; -0.256906];;
<sc30317> - : float list = [-1.; -1.; -1.; 0.]
aja has joined #ocaml
<sc30317> but it should be 0;0;0; 1
<sc30317> ?
<sc30317> haha nm
<sc30317> too tired :D
<sc30317> mrvn, that dot product you gave
yakischloba1 has quit [Quit: Leaving.]
<sc30317> does it work on 2 lists of lists?
yakischloba has joined #ocaml
<dark> it works in two lists of floats
<sc30317> ok
<dark> sc30317, why? what exactly you need?
<sc30317> like I sent in the pastebin
<sc30317> h/o
<sc30317> nm
<dark> and what is h/o?
<sc30317> a dot product of a matrix and a vector
<sc30317> h/o == hold on
<dark> no, i mean, what the my_compare needs to do?
<sc30317> never mind, I got the my_compare working
<dark> sc30317, hmm you can define dot products only for two vectors, not a matrix and a vector..
<dark> what you really want is a matrix multiplication
<dark> that can use the dot product as subroutine
<sc30317> like on this
<sc30317> under Rotation
<sc30317> never mind
<sc30317> wrong instance
<sc30317> like I sent you in the pastebin
yakischloba has quit [Quit: Leaving.]
<dark> sc30317, actually.. is the leght of the lists fixed..?
<sc30317> yes
<sc30317> absolutely
<dark> sc30317, can you tell what your company does?
<sc30317> yea
<sc30317> System Automation
<sc30317> we produce bottling lines
<sc30317> (for like your coca cola, gatorade, etc.)
tmaedaZ is now known as tmaeda
<dark> this wouldn't usually be done with C? (i study computer engineering, i might go to this area, 'automation')
<mrvn> let dotproduct = List.fold_left2 (fun x a b -> x +. a *. b) 0.0;;
<mrvn> let transpose m = List.map List.rev (List.fold_left (List.map2 (fun xs x -> x::xs)) (List.map (fun x -> [x]) (List.hd m)) (List.tl m));;
<dark> maybe your boss just love FP
<mrvn> let mul m1 m2 = List.map (fun v1 -> List.map (fun v2 -> dotproduct v1 v2) (transpose m2)) m1;;
<sc30317> haha thats what I studied in school too
<sc30317> yea I think my boss is just silly
<dark> mrvn, =o awesome
<mrvn> dark: At least you wouldn't usualy do this with lists
<dark> yes, that's what i was thinking mrvn
<mrvn> transposing a list list is a pain
<dark> ocaml is just fine for this job, but with arrays (maybe with a high memory footprint, but if you aren't in an embedded env this is fine...)
<dark> i was writing this: let rotate matrix vector = match matrix, vector with [[r1; s1; t1]; [r2; s2; t2]; [r3; s3; t3]; [r4; s4; ...
<mrvn> dark: records containing just floats and float arrays are optimized in memory
<dark> ... | _, _ -> failwith "..."
<dark> mrvn, yes, i know.. but there are the entire ocaml runtime too. plus, ocaml will not work on many (most? all?) microcontrollers
<dark> (even C will not do the job sometimes..)
<mrvn> The transpose still sucks. Should ahve used fold_right
<dark> are you thinking about performance?
<dark> i guess this is not a problem for sc30317's boss :)
<sc30317> pssh
<sc30317> probably not
<sc30317> mrvn, im sorry, I needed a matrix and a vector
<sc30317> like in my pastebin
<dark> sc30317, the problem is: if you use mrvn's code, you will _surely_ impress your boss. but this may backfire: he will a) give more job to you, that will be hard to handle, b) he will find out quickly that you haven't learned that much still (but the tip is: if you want to survive programming in ocaml, learn how to use that folds and maps effectively)
<dark> you can do mul m1 [m2]
<dark> hm no
<dark> yes :)
<sc30317> yes what?
<dark> mul matrix [vector]
<mrvn> dark: if the dminesions are right
<dark> if the dimensions are wrong, the code should just give an error i guess...
<mrvn> Exception: Invalid_argument "List.map2".
<dark> probably good enough.. one can encapsulate the code and raise a more user-friendly exception i guess..
<sc30317> yea
<dark> sc30317, when you get that code with many ( .. ), you can break it in many lines, and write begin .. end
<sc30317> ok
<mrvn> One can declare module Vec : sig type t = private float list val make : float -> float -> float -> t end = struct type t = float list let make x y z = [x; y; z] end
<mrvn> Thereby ensuring any Vec.t IS a 3 float list.
<dark> i think your boss is fairly good with FP. you should take a look in his code (if he provides some code for you..) in order to learn about his style.
<dark> hmm
<dark> :)
<dark> private?
<mrvn> dark: prevents anyone outside the module from creating a Vec.t while allowing using a Vec.t as float list.
<sc30317> ok
<dark> mrvn, very nice.. new feature? or ever existed?
<sc30317> mrvn, that mul doesn't seem to want to work when using it with a matrix and a vector?
<dark> sc30317, let mul_with_matrix_and_vector matrix vector = mul matrix [vector]
<mrvn> sc30317: obviously. A vector is a different type.
zhijie has quit [Read error: Connection reset by peer]
<sc30317> obviously
<mrvn> dark: wastefull
<dark> hmm?
<dark> why?
<mrvn> dark: because you apply List.map on a one element list
<sc30317> mrvn, how could I fix it to do a matrix dot vector
zhijie has joined #ocaml
<dark> the reason i think he is fairly good with fp is that a) if you try to program with C style, ocaml is a annoying, b) most people that love ocaml, love actually FP, c) it's said that ocaml is very fun to program... but only if you like FP. so in fact i think you can learn much reading his code sc30317
<flux> it's quite a save if developer time is a resource ;)
<mrvn> sc30317: you learn ocaml and you lookup the mathematical definition of matrix * vector
<sc30317> ok
<sc30317> thanks!
<sc30317> haha
<mrvn> dark: Unlike other functional languages ocaml has "fun".
<dark> mrvn, well, he said that the dimensions of the vector and matrix will *never* change, so in fact the general solution is overkill
<dark> yes :)
<sc30317> dark, are any of the functions you gave me good for matrix dot vector?
<dark> i really don't know how to multiply a matrix with a vector o.o
<mrvn> sc30317: the task is to write your own so you learn something.
<sc30317> im trying mrvn, its just 3:04AM here
<sc30317> and im really tired
<sc30317> and I am really close to finishing this project
<dark> i know how to multiply a AxB matrix and a Bx1 matrix
<mrvn> dark: then you only need to covert a B vector to a Bx1 matrix
<mrvn> convert even
<dark> hmm i think [vector] isn't a Bx1 matrix, it's 1xB.. then, omg
<dark> in order to use your code unchanged, maybe he needs to apply a transpose
<mrvn> dark: My mul might be transposing the wrong matrix.
<dark> and your code will apply a transpose again..
<dark> then it would be mul matrix (transpose [vector]) sc30317, but i don't have an interpreter here
<sc30317> ok ill try it
<dark> sc30317, an honest thing to say is that you couldn't finish because you don't know ocaml
<sc30317> nope
<sc30317> dark, I think your right
<mrvn> sc30317: AxB mat * B vec means building the dotproduct between every row of the matrix and the vector.
<mrvn> Just do it directly.
<sc30317> do what directly?
<mrvn> the dotproduct between every row of the matrix and the vector
<sc30317> ok
<dark> i pasted this, http://en.wikipedia.org/wiki/Matrix_multiplication#Ordinary_matrix_product , i didn't knew that the elements of the multiplication are just dot products
<sc30317> yea dark
<sc30317> what does that mean to me?
<sc30317> that is doing a 3x4 * 4x5 = 3x5
<sc30317> I am doing a 4x3 * 1x4?
<dark> you are doing a 3,4 x 4,1
<sc30317> correct
<dark> the result is 3,1
<sc30317> thats what I meant
<dark> what about this?
<dark> it's the 'dumb' version
<dark> oops, (*-) is now recognized as a comment :P
<dark> ( *- ) then
<dark> i named it rotate, i'm not sure why
<dark> i haven't tested. *- is the mrvn's dot product
<sc30317> ok
<sc30317> h/o ill test
ulfdoz has quit [Ping timeout: 246 seconds]
<sc30317> h/o ill test
<sc30317> it just prints fun
<sc30317> in the answer
zhijie has quit [Read error: Connection reset by peer]
zhijie has joined #ocaml
zhijie has quit [Read error: Connection reset by peer]
zhijie has joined #ocaml
<dark> .caml ..?
<sc30317> that is just another file that defines a matrix anddata
<sc30317> which is 4x4
<sc30317> so I just tried to do it with a 4x1
<sc30317> to create a 1x4
<sc30317> *4x1
<sc30317> and as you can see, it just shows fun fun fun fun
<dark> hmm, *- isn't defined as i thought it was
<sc30317> which is not fun :(
<dark> ah
<dark> ...
<dark> let ( *- ) a b = List.fold_left2 (fun x a b -> x +. a *. b) 0.0 a b
<dark> or let ( *- ) = List.fold_left2 (fun x a b -> x +. a *. b) 0.0
<dark> i forget to apply the fold :P
<sc30317> yup
<dark> hmm it's confusing o.o
<sc30317> that works fantastically
<dark> let ( *- ) x y = List.fold_left2 (fun x a b -> x +. a *. b) 0.0 x y
<dark> hmm
<dark> let ( *- ) m1 m2 = List.fold_left2 (fun x a b -> x +. a *. b) 0.0 m1 m2
<dark> u.u
<dark> (the fun is shadowing the a and b with its local variables)
<dark> i actually like the conciseness of let ( *- ) = List.fold_left2 (fun x a b -> x +. a *. b) 0.0
<sc30317> yea
<sc30317> that is very concise
<dark> i hope you can properly understand currying
<dark> (without that reading ocaml code can be a hard task)
<sc30317> mhmm
<dark> let f a b = a + b
<dark> let q = f 5
<dark> q is a function that sums its argument to 5
<dark> so q 6 is 11
<dark> so f 5 6 is (f 5) 6
<sc30317> ok
<dark> so if you can define let f a b = x a b, it is the same as let f = x
<dark> ocaml needs a tryocaml.org :( like tryhaskell.org and tryruby
<sc30317> ive never used either of those
<dark> it's an online interpreter
<dark> hmm i think there is a pastebin that actually interpret the code..
<sc30317> what if I want to take it down to 3 vectors?
<sc30317> just remove the u?
<dark> yes..
<sc30317> so like this?
<dark> yes
<dark> let mult matrix vector = List.map (fun x -> x *- vector) matrix
<dark> i think this work for both cases
<dark> but then you need to adjust the size of the vector accordingly
tmaeda is now known as tmaedaZ
<sc30317> yes that worked
zhijie has quit [Read error: Connection reset by peer]
<dark> http://codepad.org/32JTRnNz This function is applied to too many arguments
<sc30317> you didn't put a double semicolon at the end
zhijie has joined #ocaml
<dark> yes ^^
zhijie has quit [Read error: Connection reset by peer]
<dark> http://codepad.org/CVVuN6xG no output, but ran :P
zhijie has joined #ocaml
zhijie has quit [Read error: Connection reset by peer]
zhijie has joined #ocaml
zhijie has quit [Read error: Connection reset by peer]
<sc30317> dark, yea thats what I got
zhijie has joined #ocaml
<dark> sc30317, also http://codepad.org/DoOGC2Oo
<dark> (some minor tricks)
<sc30317> haha nice
<sc30317> this still doesn't do exactly what I need it to do though I think
<dark> :) well you need to actually do something
<dark> do you have an ocaml book?
<sc30317> yes
<sc30317> I know
<sc30317> im working on it
<sc30317> I am going to work on it tomorrow
<sc30317> its 4:00AM here :D
<sc30317> too late
<dark> 4:57 here
<sc30317> PM or AM?
<dark> am
<sc30317> yikes!
<sc30317> you couldn't sleep either?
<dark> yes..
<dark> my sleep cycle is rather random :(
<sc30317> that stinks
<sc30317> im sure you just need some exercise and good sleep cycles
<dark> exercise?
<dark> hmm
<sc30317> definitely
<sc30317> I am a huge exercise buff
<sc30317> and it helps me a ton with sleep
<sc30317> I used to have the same issue
<dark> how it will help? because after this one will be too tired?
<sc30317> haha not now
<sc30317> but on a normal basis
<dark> hm
zhijie has quit [Read error: Connection reset by peer]
<sc30317> yea
<sc30317> I gotta go catch some sleep
<sc30317> ill prob see you on here sometime tomorrow
zhijie has joined #ocaml
oc13 has quit [Ping timeout: 240 seconds]
aja has quit [Read error: Connection reset by peer]
zhijie has quit [Read error: Connection reset by peer]
<dark> bye sc30317
zhijie has joined #ocaml
drewbert has joined #ocaml
<drewbert> I just wrote my very first function in ocaml, not copied from example code, and it without errors, and tests show it worked!
<drewbert> ran without errors*
zhijie has quit [Read error: Connection reset by peer]
<Camarade_Tux> \o/
<drewbert> \o/
<drewbert> seriously, the very first thing I typed in worked. when does that ever happen?
zhijie has joined #ocaml
zhijie has quit [Read error: Connection reset by peer]
<dark> mm o.o
<dark> drewbert, once i was without a computer for some time, and started to program in my notepad..
<dark> with paper and pencil
zhijie has joined #ocaml
<dark> i choose ocaml
<dark> then ran the code, it worked flawlessly
<dark> o.o
<drewbert> dark: that's awesome.
<dark> it was some tree code, and some circular structures.. i never did that in ocaml
<dark> type 'a circular_list = 'a circular_list * 'a * 'a circular_list
<dark> or something like that o.o
<dark> or maybe type 'a circular_list = ('a circular_list * 'a * 'a circular_list) option
zhijie has quit [Read error: Connection reset by peer]
* dark trying to remember how to insert things in this list
<dark> i think that let singleton a = let rec l = l, a, l in l works, not completely sure :D
zhijie has joined #ocaml
<mrvn> Not really a list
<dark> a list in the sense i can walk it
<mrvn> Without the option you have a trie.
<dark> but tries will not stop in a certain point?
<dark> without the option i don't have a 'base case'
<mrvn> A trie stops with the leaves pointing back further up in the trie.
albacker has joined #ocaml
ygrek has joined #ocaml
pimmhogeling has joined #ocaml
zhijie has quit [Read error: Connection reset by peer]
smimram has quit [Read error: Operation timed out]
zhijie has joined #ocaml
smimram has joined #ocaml
Yoric has joined #ocaml
slash_ has joined #ocaml
bluestorm has joined #ocaml
sepp2k has joined #ocaml
ikaros has joined #ocaml
Yoric has quit [Quit: Yoric]
Scorchin has joined #ocaml
sepp2k1 has joined #ocaml
sepp2k has quit [Read error: Operation timed out]
maattd has quit [Remote host closed the connection]
Yoric has joined #ocaml
<flux> am I doing something obviously wrong here? CAMLprim caml_getifaddrs_c(value a_unit) { CAMLparam1 (a_unit); CAMLlocal1 (result); result = caml_alloc(1, 0); Store_field(result, 0, result); CAMLreturn (result); } segfaults for me.
<flux> at Store_field
Yoric has quit [Quit: Yoric]
<flux> actually I didn't mean to construct an infinite structure, but it segfaults with Store_field(result, 0, a_unit) as wel
<flux> l
<flux> need to get some other trivial c-extension and try to compile it..
Scorchin has left #ocaml []
<ygrek> thats full code?
<flux> yes
<flux> well, not including the #includes
<mrvn> Its what the docs say to do
<flux> nor the main program, but this is the first thing it does
<ygrek> btw, I already have the code to get the list of broadcast addresses, if you are interested
<flux> yes.. so I'm wondering if OcamlMakefile compiles that somehow funkily or if my compiling environment is broken for this..
<flux> I want actually the interface addresses
<ygrek> what gdb says?
<flux> it says, strangely, that result is -134608608
<flux> which surprises me, because it looks like it is 32 bits then?
<mrvn> flux: value is an integer
<ygrek> and backtrace?
<flux> #0 0x000000000071104a in caml_modify ()
<flux> #1 0x000000000070d1a9 in caml_getifaddrs_c (a_unit=1) at getifaddrs-c.c:17
<flux> mrvn, yes, but I'm on a 64-bit host, I wouldn't expect it to be negative..
<flux> or does it just keep something at the end of the address space
<ygrek> really strange
<ygrek> I mean backtrace, result is probably ok
<flux> ygrek, so did your code store interface addresses too?
<ygrek> btw, CAMLprim _value_ caml_getifaddrs_c
<flux> oh, right. that doesn't affect anything, though. (tried it)
<ygrek> maybe you get some wrong headers included? is it the only caml installation?
<flux> it is the ubuntu ocaml installation. I've got the source tree extracted elsewhere, but nothing else
<flux> and ocamlc -where points to the right directory
<ygrek> try caml_alloc(2,0)
* ygrek goes with wild guessing :)
<flux> no difference :)
<mrvn> flux: did you specify "noalloc"?
<flux> mrvn, no, external getifaddrs : unit -> ifaddr list = "caml_getifaddrs_c"
<bluestorm> maybe a build problem ?
<bluestorm> do you compile that by hand ?
<flux> bluestorm, I'm using ocamlmakefile
<flux> infact, I'll try compiling by hand now
<flux> but I don't know how it can cause this..
<ygrek> enable -Wall just in case
<bluestorm> I'd try the simplest thing first (compiling by hand)
<bluestorm> it looks like the code is right, and the problem is with your setup
<flux> hah
<flux> I think I know why it crashes
<flux> getifaddrs-c.c:19: warning: implicit declaration of function ‘caml_alloc’
<flux> OCamMakefile hides warnings :)
<flux> big mystery solved...
<mrvn> I don't get why that isn't an error yet
* ygrek always compiles with -Wall
<mrvn> The times where implicit declarations were needed because including headers would take too long or use too much memory are long gone.
smimram has quit [Ping timeout: 268 seconds]
<flux> annoyingly sockaddr.h isn't at `ocamlc -where`/caml/
<mrvn> why should it?
<bluestorm> ygrek: there is an interesting post asking user _not to use_ -Wall on the caml mailing list
Yoric has joined #ocaml
<flux> mrvn, well, how else am I going to create ocaml sockaddr-objects from C conveniently?
<ygrek> bluestorm, where?
<mrvn> flux: ahh, the problem of ocaml not exporting things to the C layer.
<flux> mrvn, the symbol is exported though. all I need to do is #include that and it links just fine.
<bluestorm> hm
<ygrek> that's ocaml warnings
<bluestorm> well
<bluestorm> actually, it's about the combination of -Wall and -Werror
<bluestorm> wich is actually not what you was proposing, my mistake
<bluestorm> but his argument (against -Wall + -Werror) applies to C as well (and basically any language)
sepp2k has joined #ocaml
sepp2k1 has quit [Ping timeout: 264 seconds]
zhijie has quit [Read error: Connection reset by peer]
zhijie has joined #ocaml
smimram has joined #ocaml
Yoric has quit [Quit: Yoric]
ikaros has quit [Quit: Leave the magic to Houdini]
maskd has joined #ocaml
bluestorm has quit [Quit: Leaving]
smimram has quit [Ping timeout: 268 seconds]
smimram has joined #ocaml
derdon has joined #ocaml
zhijie has quit [Read error: Connection reset by peer]
zhijie has joined #ocaml
zhijie has quit [Read error: Connection reset by peer]
zhijie has joined #ocaml
zhijie has quit [Read error: Connection reset by peer]
zhijie has joined #ocaml
zhijie has quit [Read error: Connection reset by peer]
smimram has quit [Ping timeout: 268 seconds]
zhijie has joined #ocaml
smimou has joined #ocaml
ttamttam has joined #ocaml
zhijie has quit [Read error: Connection reset by peer]
zhijie has joined #ocaml
zhijie has quit [Read error: Connection reset by peer]
zhijie has joined #ocaml
ikaros has joined #ocaml
tmaedaZ is now known as tmaeda
karuza has joined #ocaml
tmaeda is now known as tmaedaZ
zhijie has quit [Read error: Connection reset by peer]
zhijie has joined #ocaml
zhijie has quit [Read error: Connection reset by peer]
Yoric has joined #ocaml
zhijie has joined #ocaml
ttamttam has quit [Quit: Leaving.]
zhijie has quit [Read error: Connection reset by peer]
zhijie has joined #ocaml
derdon has quit [Quit: derdon]
slash_ has quit [Quit: Lost terminal]
drk-sd has joined #ocaml
Anarchos has joined #ocaml
tmaedaZ is now known as tmaeda
_unK has joined #ocaml
<thelema> flux: String.quote is just printf "%S"
M| has joined #ocaml
<sc30317> dark, you there?
<sc30317> or thelema, you there?
* mrvn hides behind a good book
<sc30317> haha nice mrvn
<sc30317> I just had a quick question
<sc30317> is there any way to do this?
<sc30317> mrvn, I couldn't find anything like that in a book
<sc30317> I read and practice-developed for hours
<sc30317> can anyone help?
oc13 has joined #ocaml
ygrek has quit [Remote host closed the connection]
ygrek has joined #ocaml
smimou has quit [Ping timeout: 246 seconds]
smimou has joined #ocaml
Yoric has quit [Ping timeout: 256 seconds]
sepp2k has quit [Quit: Leaving.]
sepp2k has joined #ocaml
jeddhaberstro has joined #ocaml
<flux> thelema, Printf.printf "%S" "" -> works String.quote "" -> Exception: BatInnerIO.Output_closed.
<flux> btw, how should it differ from String.escaped anyway?
yakischloba has joined #ocaml
jeddhaberstro has quit [Quit: jeddhaberstro]
lokydor has joined #ocaml
<drewbert> Hey guys I'm a beginner in OCaml. I've been looking through the tutorials trying to figure out what I'm doing wrong, but I can't figure it out. The parser just says ERROR: Syntax error. Can someone here take a look http://pastebin.ca/1846765
<flux> you are missing 'then' before 'c'
<drewbert> haha thank you so much
ikaros has quit [Quit: Leave the magic to Houdini]
<mrvn> drewbert: try not using ()
pimmhogeling has quit [Ping timeout: 265 seconds]
<drewbert> mrvn: the problem was with the "then" and adding that fixed it. I understand currying to some degree and that i'm not using it and that tuples as function arguments are not functional, but this is a school project that was assigned before we learned about them, and thus the project uses tuples.
<drewbert> tuples as function arguments are not preferable to currying*
ttamttam has joined #ocaml
slash_ has joined #ocaml
Alpounet has quit [Ping timeout: 260 seconds]
ulfdoz has joined #ocaml
Anarchos has quit [Ping timeout: 240 seconds]
ttamttam has quit [Quit: Leaving.]
lokydor has quit [Ping timeout: 246 seconds]
enthymeme has joined #ocaml
ulfdoz has quit [Ping timeout: 276 seconds]
SEcki has joined #ocaml
rwmjones has quit [Ping timeout: 245 seconds]
lokydor has joined #ocaml
<thelema> flux: odd. On my system, String.quote ""; -> - : string = "\"\""
maattd has joined #ocaml
<flux> actually
<flux> that's not the problem. it appears not to be deterministic..
<flux> if I start a new session, the first String.quote seems to work
<flux> but issuing String.quote "abc";; twice gives that error
<flux> however, BatPrintf.sprintf2 "%S" "" or "abc" works just fine many times :-o
<flux> (let quote = BatPrintf.sprintf2 "%S")
<flux> ahha!
<flux> eta-expansion to the rescue
boscop_ has joined #ocaml
rwmjones has joined #ocaml
<flux> that kind of quote-function reproduces the problem but let quote s = BatPrintf.sprintf2 "%S" s doesn't
boscop has quit [Disconnected by services]
boscop_ has left #ocaml []
boscop has joined #ocaml
<flux> doing the eta contracted version let quote = BatPrintf.sprintf "%S" works fine as well
bzzbzz has joined #ocaml
ulfdoz has joined #ocaml
krankkatze has joined #ocaml
oc13 has quit [Ping timeout: 276 seconds]
thrasibule has joined #ocaml
hcarty has quit [Quit: leaving]
bluestorm has joined #ocaml
hcarty has joined #ocaml
<hcarty> Testing...
<hcarty> Sorry for the noise. I was getting "Cannot send to channel" errors from irssi. A restart seems to have fixed it.
<flux> maybe it was the reconnect
<hcarty> flux: That is my guess
oc13 has joined #ocaml
thrasibule has quit [Ping timeout: 260 seconds]
smimou has quit [Ping timeout: 246 seconds]
<hcarty> Just completed my first real use of functors as a module writer rather than as a module consumer. Nifty stuff.
smimou has joined #ocaml
quelqun_dautre has quit [Ping timeout: 260 seconds]
quelqun_dautre has joined #ocaml
<bluestorm> hcarty: I sometimes use functors to get incompatible abstract datatypes
pimmhogeling has joined #ocaml
<bluestorm> module F (T : sig end) : sig type t ... end = struct t ... end
<bluestorm> (recently I used that trick to represent "variables" in a programming language : I needed different type of variables, so I wanted different types to make erroneous mixing impossible)
<hcarty> bluestorm: That's a good idea
<hcarty> bluestorm: I used it in this case to reduce code duplication for c_layout and fortran_layout Bigarrays
<hcarty> There are only two possible variations for this module. Is it better to expose the functor interface to the user, or apply the functor ahead of time to the two possibilities and hide the fact that this uses a function with the module's interface?
<hcarty> s/function/functor/
drewbert has quit [Quit: Leaving.]
tmaeda is now known as tmaedaZ
<hcarty> For example, provide Foo.Make, Foo.C_interface, Foo.Fortran_interface and/or provide Foo.C (= Foo.Make(Foo.C_interface)), Foo.Fortran (= Foo.Make(Foo.Fortran_interface))
<bluestorm> hcarty:
albacker has quit [Quit: Leaving]
<bluestorm> in an abstract setting, the functor would be better as it would allow the user to use your library unmodified if a other layout type was to be added to the stdlib
<bluestorm> in practice, maybe plain modules are less confusing to the user, I don't know
<hcarty> bluestorm: I may leave both. Hiding the underlying functor application is not turning out to be as simple as I had hoped
<bluestorm> and they would allow you to manually inline them while remaining interface-compatible, if you found out it was beneficial for performance
<bluestorm> hum
<bluestorm> keeping the functor also allows users to extend the library by using functors themselve
<hcarty> bluestorm: Thank you for the suggestions
schmx has joined #ocaml
schmx has quit [Changing host]
schmx has joined #ocaml
krankkatze has quit [Ping timeout: 256 seconds]
pimmhogeling has quit [Ping timeout: 256 seconds]
dark has quit [Ping timeout: 276 seconds]
pimmhogeling has joined #ocaml
rwmjones has quit [Ping timeout: 256 seconds]
drewbert has joined #ocaml
rwmjones has joined #ocaml
krankkatze has joined #ocaml
dark has joined #ocaml
dark has quit [Ping timeout: 258 seconds]
smimou has quit [Ping timeout: 246 seconds]
smimou has joined #ocaml
dark has joined #ocaml
krankkatze has quit [Remote host closed the connection]
ygrek has quit [Ping timeout: 245 seconds]
matthieu has joined #ocaml
maattd has quit [Ping timeout: 256 seconds]
oc13 has quit [Ping timeout: 248 seconds]
<sc30317> hey all
<sc30317> I have a (hopefully) very quick question
pimmhogeling has quit [Ping timeout: 256 seconds]
<sc30317> why does this function error?
<hcarty> sc30317: Why is finish declared with "let rec"?
<sc30317> hcarty, because it needs to be a recursive function
<sc30317> compare_vc_current_class compares the two vectors
<sc30317> if it is true then I want to quit
<hcarty> finish does not call itself
<sc30317> if it is false, then I want to do stuff then try the finish again
<hcarty> You don't though
<sc30317> where would I call it?
<hcarty> Also, you are missing an "in" at the end of what appears to be the definition of new_w
<hcarty> I'm not sure where you would call it as I don't know what the function is supposed to do
<sc30317> oh ok
<sc30317> hold on, ill make some changes and post more code
<hcarty> sc30317: Would some documentation/tutorial references help?
<sc30317> hcarty, I have looked through some documentation on this subject, it doesn't seem to help
<hcarty> The tutorial chapter in the OCaml manual would likely be helpful, as would http://www.ffconsultancy.com/products/ocaml_for_scientists/chapter1.html if you just want to jump in
<sc30317> hcarty, I looked at that already
<sc30317> hcarty, I am pretty sure that i am extremely close to having this right
<sc30317> Here is my latest
<sc30317> if you need any other code, i can post more
<bluestorm> you still don't need that "let rec"
<bluestorm> or maybe you want to write
<bluestorm> let rec finish () = let is_finished = compare_vc_... in if is_finished then exit 0 else .... finish ()
<sc30317> bluestorm, that would be fine
<sc30317> but I have to do stuff (as shown in lines 4 and 5 in the pastebin
<sc30317> I guess I could do it like this
<sc30317> but that errors as well
<sc30317> why
<hcarty> sc30317: What error are you getting?
<sc30317> syntax error
<hcarty> sc30317: In your latest post, you are trying to compare a function (finish) with a boolean (true)
<hcarty> What specific error?
<sc30317> Error: Syntax error
<bluestorm> what is the error position, etc. ?
<bluestorm> the code you shown looks syntaxically correct
<sc30317> hcarty, compare_vc_current_class returns true if vector_class and current_class are the same
<bluestorm> isn't the error in another part of your source file ?
<drewbert> ARGGGHHH, I cannot figure this language out.
<sc30317> the error position is right at the end of the file
<sc30317> bluestorm, because this is my last function
<hcarty> sc30317: But you aren't comparing the result of compare_vc_current
<bluestorm> well sc30317
<hcarty> That isn't a syntax error, but it will give an error (eventually)
<bluestorm> probably you forgot a "in" after a "let ..." higher in your code
<bluestorm> also, after the error hcarty noticed, there is a problem with your "w_current"
<sc30317> what is the problem?
<bluestorm> you code probably doesn't have the semantic you want : w_current should be a parameter to finish
<sc30317> correct
<bluestorm> hcarty noticed that you use "let is_finished ... in if FINISH = TRUE then ..."
<bluestorm> (btw., "= true" is tautological and useless)
<sc30317> ok
<sc30317> so what should I do instead of if is_finished = true then exit 0?
<sc30317> any my syntax error is definitely in that function
<sc30317> because if I comment it out the program runs
bzzbzz has quit [Quit: leaving]
<bluestorm> there is no syntax error in that function, because if I paste it into a toplevel, it works just fine
<sc30317> hmmm
<bluestorm> (but report unbound identifier errors)
<sc30317> yea
<sc30317> of course it would
thieusoai has quit [Quit: Leaving]
<sc30317> this is strange
<drewbert> how would one of you guys implement this simple function: (* grow_lists (x, y) -'a list * 'a list -> 'a list list - return a list of lists, where each element of x is prepended to y resulting lists must be in same order as in x - Example: grow_lists([1;2], [3;4]) => [[1;3;4]; [2;3;4]] *)
<sc30317> its frustrating too; once I get this working, my whole program will work! :D
<drewbert> I'm having a lot of trouble
<sc30317> drewbert, look for the ::
<bluestorm> drewbert: look for List.map
<sc30317> that adds something to a list
<drewbert> sc30317: I try to use :: but I keep getting type errors
<sc30317> are you mixing ints and floats?
<drewbert> no
<sc30317> bluestorm, if I pastebin my whole code, do you think you could see why this is syntaxing?
<bluestorm> drewbert: what you have to do is to return the list that, for each element of x, append to it the list y
<bluestorm> this is what List.map does, applying a function to each element of a list
<bluestorm> sc30317: yes
<drewbert> thanks sc30317, bluestorm, I'll see where I can get using map
<bluestorm> well
<bluestorm> the problem is that your "finish" code is not at the toplevel
<bluestorm> so it must be a local declaration
<bluestorm> and end with "in ..."
<bluestorm> let sde3 ... = .... let rec finish () = .... in finish ()
<sc30317> so it should be let rec finish() in?
<bluestorm> is probably what you want
<bluestorm> no, after declaring finish (), after the in, you have to write an expression
<sc30317> im confused?
<bluestorm> wich will be computed, and that will be the value returned by sde3
<bluestorm> well
<bluestorm> sc30317: what does the sde3 function return ?
<sc30317> it is supposed to return - : float list =
<bluestorm> where in your code do you specify that return value ?
<bluestorm> (I suppose you intend to return w_current, but that's just not the case with your current implementation)
<sc30317> I probably should be after the finish?
<bluestorm> yes
<sc30317> yes, that is what I intend to returnn
<bluestorm> well "exit 0" is not exactly a good idea if you want to return something
<sc30317> bluestorm, haha: I guess not
<sc30317> I didn't even think about that
<sc30317> I guess I would need something equivalent to a break?
derdon has joined #ocaml
derdon has quit [Client Quit]
<sc30317> bluestorm?
<bluestorm> hum
<bluestorm> well, you should fix that :D
<sc30317> ok
<bluestorm> as I said, what you want to return, after having declared the finish () function, is probably the result of calling finish
<bluestorm> so ... in finish ()
<bluestorm> (wich makes it syntaxically correct)
<sc30317> ok... so I would say if is_finished then .......
<sc30317> and should I be addding this at the end of my finish loop to finish my sde3 loop?
<sc30317> in
<sc30317> if sde3 = [] then failwith "no"
<sc30317> ;
<bluestorm> hm, no
<bluestorm> you have to add something _after_ finish declaration
<bluestorm> let rec finish () = ........ in
<sc30317> so like let rec finish () = in
<bluestorm> and then
<bluestorm> a return value for the whole sde3 function
<sc30317> where would I add the retutrn value for sde3?
<bluestorm> hm
<bluestorm> it seems you don't have a really clear idea of ocaml (function) declaration syntax
<sc30317> I do
<sc30317> just not in this instance
<bluestorm> in OCaml, a toplevel declaration is of the form let identifiant param1 param2 param3 = expression ;;
<sc30317> right
<sc30317> then in the next level its let x param1 param2 = expression in
<bluestorm> there is also a local declaration form, wich is an _expression_, of the form "let id p1 p2 .. = expression in expression"
<bluestorm> no, not "let ... in", but "let .. in expression"
<bluestorm> the fact that there is an expression after the "in", and that that whole construct is an expression itself, is crucial
<sc30317> what would one use for the expression?
<sc30317> I guess that is where I add the if
<sc30317> and the else
<bluestorm> well
<bluestorm> you can use that local declaration to build richer expression, that you can then put inside a global declaration
<bluestorm> eg. let a = (let b = c in d)
<bluestorm> let a = (let b = c in (let d = e in f))
<sc30317> so like my example, I could do let rec finish () in sde3 =
<bluestorm> ?
<sc30317> I thought thats what you were trying to say
<sc30317> bluestorm, you are confusing me
<bluestorm> well
<bluestorm> I described to you the syntax of ocaml global and local declarations
<sc30317> yes
Associat0r has joined #ocaml
<bluestorm> "let rec finish () in sde3 =" is not a valid declaration
<sc30317> yes I understand that
<sc30317> it would be let rec finish () =
<sc30317> then all the stuff inside
<sc30317> in
<drewbert> I've learned that I reallly cannot think of how to do stuff without side effects.
<bluestorm> drewbert: you've learned that you have to try harder
<drewbert> I've been stuck on this same damn function for hours.
<sc30317> drewbert, get used to it :(
<sc30317> bluestorm, anyway; I put that and the function finish now has a syntax error
<drewbert> something that would take me 30 seconds in c
<bluestorm> "Functional programming doesn't fit my mental model" is a lousy excuse for refusing to change one's habit
<drewbert> bluestorm: I can't find any examples either though!
<bluestorm> well
<sc30317> drewbert, at tthe start of this project, I was the same way
<bluestorm> List.map (fun x -> x + 1) [1; 2; 3] is [2; 3; 4]
<sc30317> drewbert, read through the documentation on List.map, that will help
<bluestorm> let f (li, incr) = List.map (fun x -> x + incr) li in f ([1; 2; 3], 2) is [3; 4; 5]
<bluestorm> if that can help
<bluestorm> sc30317: "let rec finish () ... in" is not a valid expression
<sc30317> bluestorm, I need to add an expression at the end
<bluestorm> yes
<sc30317> if finish() = [] then failwith "no"
<bluestorm> and that expression will be the return value of the whole sde3 function
<sc30317> so I say if finish() then ....
<sc30317> and after the .... I need to return the w_current?
<bluestorm> just to be clear : http://pastebin.com/s5bRE0sP is syntaxically valid
<sc30317> yea, but that wont return w_init, correct?
<bluestorm> no that won't
<bluestorm> this is of type unit
<bluestorm> because "if a then b" is equivalent to "if a then b else ()"
<bluestorm> and () is unit
<drewbert> let rec grow_lists(x, y) = map(fun h -> h::y, x) where map actually takes a tuple, but otherwise emulates map. I get "this expression should not be a function" error
<sc30317> ok
<sc30317> so then I need to add an else
<drewbert> hah
<drewbert> uhhh apparently i was missing parenthesis
<drewbert> let grow_lists(x, y) = map((fun h -> h::y), x) works, but I have no idea why
<sc30317> bluestorm, even doing what you just said gives me a syntax error
<bluestorm> well
<drewbert> sc30317: try adding parenthesis :-P
<sc30317> drewbert, thats not what I need
<bluestorm> fun h -> h::y, x is equivalent to fun h -> (h::y, x)
<bluestorm> because , has higher precedence than function declaration
Associat0r has quit [Quit: Associat0r]
<drewbert> bluestorm: thanks!
<drewbert> I was banging my head against the keyboard for several hours on 1 line of code ><
<bluestorm> that's an arbitrary syntaxic decision that is justified by the fact that you often have anonymous functions returning tuples, and rarely tuples of anonymous functions
<bluestorm> drewbert: in doubt, use local declarations instead of anonymous functions
<bluestorm> let grow_list(x, y) = let add_y x = x::y in map(add_y, x)
<bluestorm> (do you know about curryfication ? map in OCaml usually doesn't take a tuple as argument)
<sc30317> its saying
<sc30317> let w_current = vector_add (vector_mult(error_vect lr_matrix)) w_current in
<sc30317> This expression is not a function; it cannot be applied
<drewbert> i know of curryfication, this project was assigned before they taught it though and map is actually a function they supllied that takes a tuple
Yoric has joined #ocaml
<drewbert> for our "benefit"
<bluestorm> sc30317: this is not a syntaxic error
<bluestorm> this is a semantic error
<sc30317> bluestorm, I fixed some stuff and then that is what I got
<bluestorm> your "error_vect" is not a function, it's a non-functional value
<dark> sc30317, let .. in .. is an expression, to evaluate expressions directly you should use let _ = expression in your program (otherwise you have to put ;;, or it is likely a syntax error..)
<bluestorm> let error_vect = vector_mult lr_vector new_vect in ..
<dark> let a = 2 let b = 3 is valid; let a = 2 let b = 3 in b+1 is not; but let a = 2 let _ = let b = 3 in b+1 is
<dark> let a = 2;; let b = 3 in b+1 is also valid
<bluestorm> dark: beginners usually find the "let _ =" form disturbing
<dark> @.@ the program logic shouldn't need more than, say, one _
<dark> then _ will be the "main" ;)
<sc30317> bluestorm, that won't work either
<sc30317> because
<dark> but when i finally understood the _, i really liked it
<bluestorm> dark: I rather use "let () = ..." because I find ignoring non-unit value is not a good practice
<bluestorm> (and rather use an explicit "ignore" when I want that behaviour)
<dark> bluestorm, hm @.@
<sc30317> w_current needs to be (error_vect * lr_matrix) + w_current
<bluestorm> sc30317: I just pasted your code. I was trying to point out that in the way you declared it, "error_vect" is not a function
<bluestorm> oh
<bluestorm> I just understood
<sc30317> let error_vect = vector_mult lr_vector new_vect in
<sc30317> if error_vect = [] then failwith "error_vect cant be empty"
<sc30317> ;
<sc30317> ?
<bluestorm> vector_mult(error_vect lr_matrix)
<sc30317> yes
<bluestorm> you don't actually mean vector_mult(error_vect(lr_matrix))
<sc30317> no
<bluestorm> well that is what you wrote
<sc30317> sorry
<sc30317> let w_current = vector_add (vector_mult(error_vect lr_matrix)) w_current in
<bluestorm> you want (vector_mult error_vect lr_matrix)
<sc30317> ok changed
<dark> ps: finish is a function? it does not receive a parameter. so you understand currying better now, right? o.o' (but if finish is a function, you can't compare it with true). also i think you don't need rec to do things like let a = b in a x
<bluestorm> in OCaml, f x is equivalent to f(x)
<bluestorm> so f(g x) is equivalent to f(g(x))