mbishop changed the topic of #ocaml to: Discussions about the OCaml programming language | http://caml.inria.fr/ | Grab OCaml 3.10.2 from http://caml.inria.fr/ocaml/release.html (featuring new camlp4 and more!)
<thelema> let gen_list f len = List.map (fun _ -> f ()) (0--len)
<palomer> is there an advantage to using type a = `FOO a | `BAR as opposed to type a = Foo a | Bar ?
* palomer would do everything with polymorphic variants if he could
<thelema> palomer: yes, but there's dangers as well.
<palomer> what are the dangers?
<qwr> palomer: some potential errors cannot be checked with polymorphic variants
<palomer> but they're so much more flexible!
<thelema> yup, and that's why they're not quite as safe.
<palomer> and they don't pollute the namespace
<palomer> can you give me an example of potential pittfalls?
<thelema> when matching, you're not forced to match everything, and if you misspell one, it'll be allowed
<thelema> (usually)
<thelema> let f = function `FOO x -> "foo" | `BRR -> "bar"
<thelema> the compiler usually won't catch that error there.
<qwr> thelema: you can't give `BAR to that f
<qwr> but compiler will not catch that, if you have | _ -> "zzz" also ;)
<alexyk> when I access Str from toplevel, I do #load "str.cma";; -- but if I try to compile a file with it I get a syntax error on that line, why?
<thelema> alexyk: because you can't do # declarations outside the toplevel.
<qwr> alexyk: becouse those #directives are not part of ocaml language
<thelema> alexyk: the way to use str.cma from a compiled program is to link with them
<thelema> ocamlc str.cmxa myprog.ml
evn_ has joined #ocaml
<alexyk> right -- so I guess the way to develop is to issue # directives manually in tuareg's toplevel, leaving them off the files, right? I also saw them in Markus's shell scripts, but I guess that's because they start with #!...ocaml
<qwr> palomer: http://caml.inria.fr/pub/docs/manual-ocaml/manual006.html discusses the weaknesses of polymorphic variants
<qwr> palomer: but those variants are still nice ;)
<alexyk> thelema: I get partial application warning on our
<alexyk> let vals = Str.split whitespace line in
<alexyk> List.iter (print_int |> int_of_string) vals
<alexyk> at int_of_string
<alexyk> is there a way to hint ocaml something, instead of -w f ?
<qwr> alexyk: you shouldn't get that warning ;)
<alexyk> qwr: umm, but I do! If we define |> as compose and use it naturally as above...
<thelema> because iter expects void, and ... how do you have |> defined?
<qwr> print_int is int -> unit, so everything should be nice
<qwr> # let vals = Str.split (Str.regexp "[ \t]+") "1 2 3" in List.iter (print_int |> int_of_string) vals;;
<qwr> 123- : unit = ()
<qwr> # let (|>) f g = function x -> f (g x);;
<alexyk> let (|>) f g = function x -> f (g x)
<alexyk> yep
<alexyk> I have it defined outside let main () = ...
<thelema> alexyk: well then let's try skipping the |> and write simply (fun is -> print_int (int_of_string is))
* qwr . o O ( could also be let (|>) f g x = f (g x) )
<alexyk> I'm now wondering if F# defines its forwards, as we want to pipe things left to right to look unixy, not mathy
<alexyk> -- want to define |> in ocaml, not F# of course, it's predefined there
<qwr> possible, but it won't matter here
<alexyk> qwr: yes
<alexyk> ok here's the whole original script, very short:
<alexyk> let whitespace = Str.regexp "[ \t]+"
<alexyk> let (|>) g f = function x -> f (g x)
<alexyk> let main () =
<alexyk> let rec do_line ic =
<alexyk> try
<alexyk> let line = input_line ic in
<alexyk> let vals = Str.split whitespace line in
<alexyk> List.iter (int_of_string |> print_int) vals; print_newline;
<alexyk> do_line ic
<alexyk> with End_of_file -> ()
<alexyk> in
<alexyk> do_line stdin;;
<alexyk> main ()
<alexyk> with |> now pumping forward
<alexyk> gives partial warning on print_int
<alexyk> -- works OK
<qwr> print_newline
szell has quit [Read error: 110 (Connection timed out)]
<qwr> is your problem
<qwr> and no, it don't work
<alexyk> qwr: of course
<alexyk> ()
<alexyk> we just talked about
<qwr> that print_newline just sits there emitting it's function value into outer space or something ;)
szell has joined #ocaml
<alexyk> works without () :)
<thelema> alexyk: I don't believe you on that.
kopophex has quit [Connection timed out]
<alexyk> thelema: wanna bet? It prints numbers on my Mac OSX with 3.10.1
<qwr> alexyk: of course. but not the newline
<alexyk> works without the newline :)
<alexyk> ok, with () works fine as expected
<qwr> those parts that don't give warning work ;)
<alexyk> so I join print statements with ; and it works here without begin...end wrap -- when woudl I need to use begin...end? found I need it in if/else, what's the justification for the difference?
<qwr> alexyk: put some print_endline "line done" after try with ;)
<ikatz> alexyk: it has to do with precedence i believe
vincenz_ is now known as vincenz
<qwr> alexyk: basically yes, ()/begin end allow grouping a part of expression
<qwr> alexyk: differently than it would be grouped by default rules
<qwr> alexyk: (in the grammar)
<ikatz> since you can create an if/else without the else, the compiler looks for an else after the statement that follows the if
<ikatz> if you have a semicolon and another statement, it assumes that the else is implicit
<ikatz> and (hopefully) gives you an error before you get into trouble at runtime
<alexyk> ikatz: ok
<qwr> match Some x -> (match x with 33 -> "a" | _ -> "z") | None -> "..."
<qwr> this would be incorrect without parenthesis
<thelema> qwr: match Some 33 -> "a" | Some _ -> "z" | None -> "..."
<thelema> :)
<Ramzi181> Can you explain the error? Where is the type unit?
<qwr> thelema: yes, this can be simplified so ;)
<thelema> Ramzi181: comingfrom t shouldn't have a ; after it.
<thelema> or you should do "match l with [] -> ()" to return unit
<Ramzi181> I don't understand.
<thelema> comingfrom returns [], the empty list.
<thelema> you probably want it to return (), unit.
<Ramzi181> Why does the semicolon there hurt? Also, I don't care what the return type is.
<thelema> because you have "comingfrom t;" ocaml expects a unit return type.
<qwr> Ramzi181: btw I suggest you avoid the list @ [ element ] pattern
<qwr> Ramzi181: it's terribly ineffective
<Ramzi181> why does ocaml expect a unit return type?
<Ramzi181> qwr: Yes, I understand.
<thelema> Ramzi181: because that's what functions that don't return anything return.
<qwr> Ramzi181: as it copies whole list each time and gives you so O(n^2)
<Ramzi181> thelema: But my function returns []
<Ramzi181> thelema: I could have had it return 5 if I so chose, right?
<thelema> Ramzi181: which has type 'a list, not unit. If you want to avoid the warning, return ()
<qwr> Ramzi181: and x = false is usually written as not x
<thelema> the warning is so that you don't do things like "print_string; print_int 4; print_newline;
yangsx has joined #ocaml
<qwr> Ramzi181: ah. unit comes actually from line 18
<thelema> qwr: = false seems reasonable to me.
<thelema> there is a problem on line 18 as well.
<qwr> Ramzi181: first if unifies with ()
<Ramzi181> i don't know what that means.
<thelema> no, there's no problem other than because comingfrom's return type is 'a list, paths_helper also has return type []
<qwr> Ramzi181: so the comingFrom result type gets unified also with unit
<qwr> Ramzi181: but it really wants to be list
<thelema> qwr: no, it is a list, and warnings get emitted when you try to use it in a ; context.
<qwr> Ramzi181: as one of the paths_helper return values is comingFrom application
<thelema> Ramzi181: change line 2 from [] to (), and this warning will go away
<qwr> yes
<thelema> maybe even error, as you're not allowed to have if foo then 5; (you have to have an else case if your then case returns a value (other than unit))
* qwr just started to think, wtf that comingfrom needs to return [] ;)
<qwr> and yes, if without else really has implicit else () ;)
psnively has quit []
<Ramzi181> Thank you guys again so much.
<Ramzi181> I'm going to take a break. I might be (probably am) done for tonight.
seafood_ has quit []
<alexyk> if I have a list [1;2;3], what's the fastest way to assign the three members to a,b,c?
<alexyk> I'll read millions of lines with three fields and split them with Str.split to get a list each time
<qwr> let [a;b;c] = l
<alexyk> so I want to avoid memory churn
<alexyk> would using scanf instead of Str.split be more efficient?
<alexyk> qwr: thx! I guess it's a short list so it won't be too inefficient over scanf
<qwr> alexyk: although you may use match l with [] -> wtf; [a;b;c] -> ... to avoid partial-match warnings
<qwr> damn. match l with [a;b;c] -> ... | _ -> wtf
<alexyk> qwr: yep, cool
<alexyk> qwr: but that screws up the code layout, everything gets stuck into ->, prolly better scanf then
AxleLonghorn has joined #ocaml
AxleLonghorn has quit [Client Quit]
AxleLonghorn has joined #ocaml
AxleLonghorn has quit [Client Quit]
evn_ has quit [Read error: 104 (Connection reset by peer)]
evn_ has joined #ocaml
<thelema> alexyk: the minor heap collector is *very* efficient at collecting ephemeral objects -- don't worry about them.
seafood_ has joined #ocaml
<alexyk> a bit more fp question -- I'm scanning lots of integers, and print them back N on a line. FP style is to pass the counter along as another argument, do modulo N and print if 0. Now I have 3 such parameters telling me when to print what. In python an easy global would do. What alternatives do we have in FP but tacking on accumulator arguments one after another?
<alexyk> It also complicates branching as I have to repeat most of the arguments save for a few which change in each particular branch
<Smerdyakov> You can probably use a higher-order function, where all these parameters will live in a closure passed to that function.
<Smerdyakov> I'm not sure if that actually makes any sense, but it's hard to provide suggestions without a concrete problem you're trying to solve. :-)
alexyk has quit []
pants1 has quit ["Leaving."]
schme has joined #ocaml
<Ramzi181> I don't think I'm getting this return type conflict thing.
<Ramzi181> The only return type is an int list, as on line 21.
<Ramzi181> Does enterring a recursion count as a return type?
middayc has quit []
<Ramzi181> thelema: are you there?
evn_ has quit []
<thelema> Ramzi181 am now.
<Ramzi181> yay
<Ramzi181> I don't get the whole return type thing.
<Ramzi181> So, a function needs to return the same type consistently.
kopophex has joined #ocaml
<Ramzi181> That way Ocaml can deduce what the return type is.
<thelema> each path through your code ends in an expression - the value of that expression is the return type of the function.
<thelema> yes, a function only gets one return type
<Ramzi181> right. so I want to ensure that my "last expression" everywhere is the same type.
<Ramzi181> Can I request you to put little markers where my possible "last expressions" are?
<thelema> in paths_helper?
<Ramzi181> uh, yes please.
<thelema> L21 & L24
<thelema> I'd remove the extra ; at the end of both those lines.
<Ramzi181> I admit L21 to be a return line, but where else?
<thelema> ah, you need one more branch on your if statement.
<thelema> what should it do if f m n = true?
<Ramzi181> the L19 if?
<thelema> i.e. what should it return?
<Ramzi181> it should skip those lines
<Ramzi181> hmm
<Ramzi181> so there is an implicit else that returns type unit, here?
<thelema> if you don't put else, there's an implicit "else ()"
<Ramzi181> so now all outlets return an int list, right?
<thelema> do you want paths_helper to return something?
<Ramzi181> i want paths_helper return a list of ints
<thelema> when it does that on l23, what do you want to do with that list of ints?
<thelema> right now, the implicit "else ()" on that line tries to make the return value of paths_helper ()
<Ramzi181> damn
<Ramzi181> Is that warning dangerous?
<thelema> it means that it'll throw away the return value of paths_helper on L23
<Ramzi181> why?
<thelema> because you're not telling it what to do with it, you're just saying do paths_helper, and then if m>1 do paths_helper again (and return that result)
<Ramzi181> Notice here: http://codepad.org/FSFoLbnS If I take out the parens on line 28 it says wrong number of arguments
<Ramzi181> I don't understand. paths_helper will return an int list. And the else will return an int list.
<thelema> you're trying to apply sum to 5 arguments, when it only takes one.
<thelema> you mean sum (paths_helper ...)
<Ramzi181> yes, but paths_helper takes the 3 arguments. i think ocaml should be able to deduce that
<thelema> If you think a little bit, you can create a case that's ambiguous.
<thelema> (I think)
<Ramzi181> can you overload functions?
<thelema> in any case, ocaml works kinda like lisp - the first value is the function, the rest are arguments.
<thelema> probably not in the way you're thinking - how would type inference work?
schme has quit [Remote closed the connection]
<Ramzi181> well, if you can't overload, then I cannot think of an ambiguous case
<Ramzi181> i'm not sure if that's important, now, though. i'm more concerned with understanding the nature of this warning.
<Ramzi181> On what line am I returning type unit?
<thelema> on line 23, you should return type unit so it can be safely ignored.
<qwr> Ramzi181: you can't overload. but every function really has only 1 argument ocaml.
<Ramzi181> lol. I thought we just agreed that the return type of a function has to be consistent. I'm returning an int list in other places. It would be inconsistent to return a unit.
<qwr> Ramzi181: and the type system don't allow direct union types
<thelema> Ramzi181: yup. so you need to do something with the returned value, and not just ignore it.
<qwr> Ramzi181: and multiple arguments are really a curring magic
<thelema> maybe you want to concatenate the two returned lists?
<Ramzi181> i'm not ignoring it. it gets returned. i'm only returning 1 list.
coucou747 has quit ["bye ca veut dire tchao en anglais"]
<qwr> Ramzi181: without parens, as you wrote it will parse as ((((sum paths_helper) m) n) [(m,n)])
<thelema> qwr: thank you, but you're not helping.
<thelema> Ramzi181: line 23 calls path_helper, right?
<Ramzi181> agreed
<thelema> and path_helper returns a list
<Ramzi181> agreed
<thelema> so what do you do with that list?
<Ramzi181> return it
* qwr is sleepy and tried to explain why ocaml requires parens there :)
<thelema> no, you return the lst generated by path_helper on L24
yminsky_ has quit []
<thelema> *list
<Ramzi181> okay, so the list created by line 23 goes no where
<thelema> yup. and that's what the compiler warns you about.
<thelema> let's talk about count for a second.
<Ramzi181> Line 20 doesn't ever get returned. Why isn't there a warning on that?
<Ramzi181> That is, what's wrong with created a list that "goes to waste."
<thelema> comingFrom returns unit
<qwr> Ramzi181: unit can be wasted ;)
<Ramzi181> hmm, so if I through in 5 somewhere in the code, that would get a warning also.
<Ramzi181> unit can be wasted...
<thelema> and if you want to ignore the result of something without a warning, do "ignore(code returning something)"
<qwr> if n > 1 then ignore (paths_helper m (n-1) (path @ [(m,(n-1))]));
<thelema> but I don't think that's what you want to do. lets talk about count.
<Ramzi181> Okay.
<thelema> you're trying to accumulate a 1 for each time m=1 and n=1?
<Ramzi181> yes
<thelema> you want to push a 1 onto count?
<Ramzi181> yes
<thelema> then you want let count = ref []
<thelema> so it's mutable.
<Ramzi181> is that a variable?
<thelema> and then count := 1::!count
<Ramzi181> I have instructions to not use variables.
<thelema> it's changable like variables in other languages
<thelema> ah, then you can't do that with count.
<Ramzi181> yes. a mutable type makes a lot of sense here, really it does.
<Ramzi181> but craziness should still compile anyway. :-P
<Ramzi181> qwr: your use of ignore didn't quite work.
<qwr> Ramzi181: should silence compiler. i really didn't read your code enough to understand its intent.
<qwr> Ramzi181: and i omitted else []
<Ramzi181> the way I'm seeing it, between lines 23 and 24, there are 4 statements. the first if, the first else, the second if, and the second else.
<qwr> if else is one expression
<Ramzi181> all of them are achievably ... oh, the first else also can never be last
<thelema> okay, if you want to do this without a "variable", you need to pass your partially collected list into paths_helper so it can add to it,
<qwr> and there is no such thing as statement
<qwr> ;)
<thelema> and then return the final list at the end.
<qwr> but yes, both if's have 2 branches
<thelema> quit it with the ignore, that won't get you where you want.
<Ramzi181> thelema: i'm not opposed to discussing the logic or implementaion, but I'm interesting in learning why syntactically what i have is wrong.
<thelema> you have to use the return value from paths_helper each time.
<thelema> sorry, I'm pushing you towards what I now classify as "completing an assignment"
<Ramzi181> between lines 23 and 24 there are 4 "branches," then. and the "branches" on line 23 can never be the return value, because line 24 will always get executed.
<qwr> Ramzi181: thelema is right in that ignore probably gives incorrect end result for your intent. but you still cant hide else into parenthesis like you did there. it belongs to the if ;)
<Ramzi181> I still have time. There is no imperative, yet.
<thelema> the value of paths_helper comes from the top-level if statement.
Mr_Awesome has joined #ocaml
<qwr> Ramzi181: you could just omit it wholly meaning the if has else ()
<thelema> (if m=n&&n=1 ...)
<thelema> err, s/statement/expression/
<thelema> it either evaluates the 'then' branch or the 'else' branch.
<thelema> to evaluate the else branch it has to evaluate another if statement
<Ramzi181> you'll probably hate this, but.
<thelema> (the if f m n = false) statement
<Ramzi181> when I removed the else [], knowing full well there is an implicity else (), and just applied the ignore to the if, it worked.
<thelema> yes, right now L23 returns unit.
thermoplyae has left #ocaml []
<qwr> Ramzi181: ignore after the else? it's exactly what i suggested first ;)
<qwr> damn. ignore after then
<thelema> qwr: no, he has if n>1 then ignore (blah);
<qwr> thelema: yes. that's what i meant.
<thelema> if n>1 then ignore (blah else []); doesn't work because (blah else []) doesn't have meaning.
<Ramzi181> so ignore can only be applied to one statement at a time?
<Ramzi181> i mean, when i had else [], why couldn't I throw that in the ignore also?
<qwr> Ramzi181: ignore can be applied only to value
<thelema> one expression.
<Ramzi181> what do you mean value?
<thelema> and you can't just put "else []" in an arbitrary expression
<qwr> Ramzi181: and else is nothing meaningful without if
<Ramzi181> if x = true 2 else 2.0
<qwr> Ramzi181: (if ... then ... else ...) is single syntactic construct, where the last else part is optional (defaulting to else ())
<thelema> if x = true then 2 else 2.0 ?? can't do -- has to return a single type
<Ramzi181> let's say my return type of a function was a list, or something.
<Ramzi181> so i want to ignore the whole thing
<thelema> s/return/evaluate to/
<Ramzi181> can't i do ignore(if x = true 2 else 2.0)
<thelema> no, the inside doesn't typecheck. 2 isn't the same type as 2.0
<thelema> treat ignore as a function (fun x -> ())
<Ramzi181> i don't think the else [] is arbitrary. i didn't have it there before, but i wanted uniformity in returning a list always. but then i went and learned that I get warnings for wasted values. that is, the only thing you can waste is a unit.
<qwr> Ramzi181: both branches must have same type
<Ramzi181> okay, I had if "a list" else []. why was ignore(if "a list" else []) bad?
<thelema> L23 isn't involved in returning a value in paths_helper (because of the ; at its end)
<qwr> Ramzi181: because if-then-else as expression as single type
<thelema> Ramzi181: if true then [2;3;4] else [] -- this is ok.
<qwr> Ramzi181: ignore (if condition then list1 else []) is ok
<qwr> Ramzi181: its just more code than if condition then ignore list
<Ramzi181> I had ignore(if condition then list1 else [])
<Ramzi181> and it didn't work
<thelema> Ramzi181: I saw: if condition then ignore(list1 else [])
<Ramzi181> oh.....
<qwr> ... where the thing in parens is just not a valid expression (it won't parse)
<Ramzi181> the return type isn't list1, the return comes from the if.
<Ramzi181> wait, wahh. then why does if condition then ignore(list1) work?
<Ramzi181> oh, let me explain
<qwr> Ramzi181: because it's short for if condition then ignore(list1) else ()
<Ramzi181> ignore(list1) turns that into a unit, so the if returns a unit. but if the else was inside of the ignore, then the else would return a unit and... shouldn't the if return a unit also?
<qwr> it will
<Ramzi181> if n > 1 then ignore (paths_helper m (n-1) (path @ [(m,(n-1))]) else []);
<Ramzi181> what does the if return?
<Ramzi181> or, in our new shorthand..
<qwr> type error ;)
<thelema> Ramzi181: type error - the first branch (), the second []
<Ramzi181> if condition then ignore (list 1 else [])
<Ramzi181> how does the second branch return []? it's in the ignore
<thelema> oops, no, can't do that. syntax error
goalieca has joined #ocaml
<thelema> (sorry, there's lots of parens, we thought the ignore ended before the else.
<Ramzi181> okay
<Ramzi181> so where does the syntax error come from?
<thelema> the bit inside the ignore: foo else []
<qwr> Ramzi181: what should (list 1 else []) mean as a standalone expression?
<Ramzi181> doesn't that mean, "turn foo into a unit, and then turn else [] into a unit"
<qwr> what else?
<thelema> nope.
<Ramzi181> hmm
<Ramzi181> i see your point, qwr. the else is meaningless without the if.
<Ramzi181> so you can only pass whole statements into ignore
<qwr> yes
<thelema> expressions
<Ramzi181> lol
<Ramzi181> so you can only pass whole expressions into ignore
<Ramzi181> and i was passing this incomplete expression.
<qwr> Ramzi181: ignore is just a function
<qwr> # ignore;;
<qwr> - : 'a -> unit = <fun>
<thelema> qwr: actually it's builtin magic, but it's nearly identical to (fun _ -> ())
<Ramzi181> I think I understand it now. And there are many ways I could have done it.
<thelema> the compiler optimizes it specially.
<qwr> thelema: imho the magic can be considered to be optimisation ;)
<Ramzi181> I could have put the entire expression in the ignore, or I could just put list1 in the ignore, and let the implicit else return a unit
<thelema> Ramzi181: exactly.
<Ramzi181> I really like you guys as teachers.
<thelema> you don't always get teaching on #ocaml - sometimes you get Smerdyakov.
<mbishop> heh
<Ramzi181> the atmosphere in here is much better than other rooms, I think.
<thelema> (Not that he's bad - he knows tons more about code correctness than I, he just doesn't teach much.)
<Ramzi181> My experience in C and Ruby rooms is, you have to know so many little details, and no one will explain nuances without telling you to switch majors.
<thelema> there's advantages to a quieter room
<Ramzi181> I think it's the nature of the language.
<thelema> OCaml - the programming language for teachers?
Traveler has joined #ocaml
Traveler is now known as Ramzi
<Ramzi> Was I kicked or disconnected?
<qwr> neither
<Ramzi> oh look, I'm still in.
Ramzi181 has quit [brown.freenode.net irc.freenode.net]
ertai has quit [brown.freenode.net irc.freenode.net]
<Ramzi> I'm sorry, did anyone reply to my generalizations?
<thelema> OCaml - the programming language for teachers?
ertai has joined #ocaml
Ramzi181 has joined #ocaml
<Ramzi> haha what's going on.
<dobblego> netsplit
<Ramzi> thelema: yes, I think people who use OCaml have been in the classroom for longer...
ertai_ has joined #ocaml
ertai has quit [Read error: 104 (Connection reset by peer)]
<Ramzi> that's my impression anyway.
* thelema learned OCaml outside the classroom.
<Ramzi> did you do post grad?
* qwr certainly isn't. but i'm just interested in functional programming
* thelema just has Bachelor's degree
<Ramzi> hmm, maybe it's the nature of functional programming that attracts a certain kind of croud, then.
<Ramzi> since i entered college I've heard CS majors complaining about OCaml.
<Ramzi> But I'm having a very positive experience with it.
<Ramzi> Some of my functions work correctly on the first run. That happens so rarely in other languages.
<thelema> Ramzi181: strong typing does that - if you ever program in Ada, similar things happen - once it compiles, it probably works.
<thelema> I think it's more so in OCaml because it has better types
<Ramzi> i'm not familiar with Ada, so I won't comment.
<palomer> and errors are easy to catch!
<Ramzi> but i clearly prefer strong type to loose type.
<palomer> (they rarely stump me for more than 10 minutes)
<thelema> and the earlier one catches errors, the less one pays for them.
Ramzi181 has quit [brown.freenode.net irc.freenode.net]
<Ramzi> thelema: it appears that my function is returning 0. do you think my sum function is wrong, or am I not adding ones to count correctly?
<Ramzi> it's funny to see myself keep quitting irc
<thelema> Ramzi: you're not adding ones.
<palomer> I met a ruby programmer the other day, he told me he does 4 levels of unit testing
Ramzi181 has joined #ocaml
<Ramzi> i mean, pushing ones
<palomer> he actually told the whole party, but I'm the only one who understood
<Ramzi> hahaha
<thelema> you're not pushing ones correctly.
* qwr has lovely memories about C daemons with slightly misdirected pointers... that was something to debug for hours ;)
<thelema> the else [] resets the count of ones you've accumulated.
<thelema> why accumulate a list, only to sum it? why not just accumulate the sum? (count + 1)
<Ramzi> i don't understand. what gets set to count+1?
<Ramzi> i just realized I must have said "I don't understand" like 400 times in this chat.
<thelema> your goal is to count the paths, no?
<Ramzi> yes.
<thelema> so why do you make a huge list, and then count how many elements are in it?
<Ramzi> because i can't use variables.
<thelema> why not count +1 each time you would add a list element?
<Ramzi> and store it where?
<thelema> same place your partial sums get stored in sum
<qwr> looking at the current code... why is this count = [] constant useful?
<Ramzi> hmm, so I would have to add a parameter
__suri_ has quit []
<Ramzi> no, i'm not seeing it
<Ramzi> i only want to increment the part sum in the top if
<Ramzi> that is, when m and n = 1
<Ramzi> i can't keep a partial sum as a parameter, because i never pass that around afterward
<thelema> you'll need to pass it around.
* palomer remembers the good old days of getting brainfudged by this stuff
<thelema> qwr: it's not -- beginner code
<Ramzi> does the function need to be completely rewritten?
<thelema> palomer: it's quite an experience going through this. I remember hitting the ocaml manual over and over to pick out pearls of wisdom from it.
<thelema> Ramzi181: not completely.
<palomer> it's like a completely different way of thinking, and you can never go back!
<thelema> palomer: you can go back - you're just adding another tool onto your toolbelt.
<palomer> haskell programming is similar, they just combine combinators ad absurdum
<palomer> every time I go back I'm like "where are my datatypes???!"
<thelema> haskell and absurdum seem to go together well.
<thelema> as far as I can tell.
<Ramzi> is the highest number of elements in a list i can ever return is 1?
<thelema> ram in your current program, yes.
Ramzi181 has quit [Connection timed out]
<Ramzi> i see
<Ramzi> hahah and there i quit again
<palomer> zip flip $ concat map foldl (foldr const `mplus`) map <--typical haskell code
<thelema> you're either returning [1] (= 1 :: count = 1 :: [] = [1]) or you're returning []
<thelema> palomer: yup, lots of combinators
<thelema> Ramzi: make count a paramater of your function.
<Ramzi> I think I need to add a parameter, check if m and n *will be* 1, and push onto count in the else if
<thelema> and think about it returning an int
<thelema> no, you can use the same structure of ifs you have now.
<Ramzi> the line (1 :: count) needs to be taken out
<Ramzi> and moved down
<thelema> and think of count as an int (the number of paths so far).
<Ramzi> no no
<thelema> replace 1::count with count+1
<Ramzi> this is the number of paths that reach 1 1
<thelema> yes, number of paths that reach 1 1
<Ramzi> okay, i did the replacement
<Ramzi> ohhhh
<thelema> now you need to figure out what to do on your n>1 and m>1 cases
<thelema> :)
<Ramzi> so count is an int...
<qwr> palomer: getDict dict >>= maybe (say to error) update . M.lookup (lower key) . fst
<Ramzi> and path_helper will return an int
<thelema> yes...
<Ramzi> i could take that ignore out, now, i think
<thelema> yes, you'll need to pay attention to what it returns...
<Ramzi> so in the n>1 line i'm getting back an updated value of count
<thelema> yes...
<Ramzi> so I could use the whole line as the argument for the m > 1 line
* qwr . o O ( haskell has good support for pointlessness contests :P )
<thelema> maybe use let to give that a name
<thelema> let count1 = if n>1 then ... else count
<Ramzi> would that be a variable
<thelema> no, simply a let binding.
<Ramzi> let me paste the wording of the instructions
<Ramzi> Do not use any imperative style in your programs . (i.e., no loops or assignments changing the value of symbols)
<thelema> this is functional style.
<Ramzi> okay
<Ramzi> and i end the let with in
<thelema> :=, for, while are forbidden.
<thelema> yes
<Ramzi> so now count1 is the arg for the next line
<Ramzi> and the else should be...
<thelema> :)
<Ramzi> else count1
<Ramzi> woah look at that
<thelema> do your brains feel any squishier?
<palomer> thelema, do you know if it's possible to put markup inside label text?
<thelema> markup inside function labels?
<thelema> like HTML?
<palomer> I mean gtk labels
<Ramzi> i was gonna say, it feels like there are stack frames dancing in my brain
<Ramzi> insightful that you'd comment on my brains
<thelema> hmmm... I don't know.
<thelema> Ramzi: it was about now that the dancing stack frames got me too.
<palomer> found it, seems you can
<thelema> palomer: there is a simple markup that's allowed in
<thelema> you got there first.
<Ramzi> about now in my code, now in the night, or now in refernece to when you were a beginner?
<thelema> now in reference to when I was a beginner.
Mr_Awesome has quit ["aunt jemima is the devil!"]
<thelema> you're short an argument on line 18
<Ramzi> count1 definitely gets set to an int
<Ramzi> oh right
<Ramzi> hmm, that error wasn't very clear
<thelema> you learn to decipher them with practice
<thelema> lots of practice
<Ramzi> success
<Ramzi> thelema, i am a big fan of yours. i'll talk to you later. goodnight.
<thelema> 'nite
Ramzi has quit ["Java user signed off"]
* palomer wonders where his fans are
<thelema> palomer: back in the haskell world?
<palomer> I'm a very small fish in the haskell world
<palomer> tiny!
<palomer> I once tried to embed mu calculus with GADTs
<palomer> (which failed)
<thelema> #ocaml is a small world, I guess
<palomer> google says ocaml is more popular than haskell
<palomer> but the #ocaml channel is smaller
<palomer> (google also says that sml is more popular than haskell)
<thelema> more people using it privately, less using it publicly?
<thelema> (it=ocaml)
kelaouchi has quit ["leaving"]
|Catch22| has quit []
mwc has quit [Remote closed the connection]
seafood_ has quit []
seafood_ has joined #ocaml
palomer has quit [Remote closed the connection]
rey_ has quit [Read error: 110 (Connection timed out)]
ttamttam has joined #ocaml
ttamttam has left #ocaml []
Demitar has quit [Read error: 110 (Connection timed out)]
seafood_ has quit []
alexyk has joined #ocaml
<alexyk> greetings -- am trying do do a smart initializer for three formats
<alexyk> let [intC;intR;intV] = List.iter (fun x -> let s = "%"^(string_of_int x)^"d" in format_of_string s) [6,7,2]
<alexyk> yet it gives a type error -- why?
<alexyk> er, few things are fixed in the above. the heart of the problem is
<alexyk> let s = "%"^(string_of_int x)^"d" in format_of_string s)
<alexyk> marks s as: This expression has type string but is here used with type
<alexyk> ('a, 'b, 'c, 'd, 'e, 'f) format6
ttamttam has joined #ocaml
ttamttam has left #ocaml []
Tetsuo has joined #ocaml
ikaros has joined #ocaml
<rwmjones> alexyk, you just can't construct format strings at runtime
<rwmjones> they have to be type-checked at compile time
<alexyk> rwmjones: arrgh! that's annoying... I need to concoct formats to write fixed-width field, and the width is computable
<alexyk> rwmjones: btw, are you the richard jones? :)
<rwmjones> the whole point of ocaml are the compile-time guarantees ... however in this case just use a padding function, I have one:
<rwmjones> line 107
<rwmjones> who is 'the' richard jones?
<alexyk> the unfortunate Practical OCaml reviewer :)
<alexyk> kidding -- I read the merjis blog on that...
<alexyk> actually, I should have said the author of the great pgocaml
<alexyk> thx for the function!
<alexyk> how do I just issue a string into a channel, no formatting?
<alexyk> (since I don't need it anymore)
OChameau has joined #ocaml
bongy has joined #ocaml
<tsuyoshi> haskell seems like the new lisp
<tsuyoshi> lots of people are into it but not too much actual software written
<rwmjones> alexyk, you mean output_string?
<alexyk> ah, yes
<alexyk> I think -- now that I have the padded string, I can just use that instead of Printf.fprintf, correct?
hkBst has joined #ocaml
alexyk has quit []
goalieca has quit [Remote closed the connection]
yangsx has quit [Read error: 110 (Connection timed out)]
Yoric[DT] has joined #ocaml
kopophex has quit [Connection timed out]
Yoric[DT] has quit ["Ex-Chat"]
ikaros_ has joined #ocaml
ikaros has quit [Read error: 110 (Connection timed out)]
bongy has quit ["Leaving"]
coucou747 has joined #ocaml
ita has joined #ocaml
bla has quit [No route to host]
Yoric[DT] has joined #ocaml
bla has joined #ocaml
bongy has joined #ocaml
ygrek has joined #ocaml
ikaros_ has quit ["segfault"]
ikaros has joined #ocaml
schme has joined #ocaml
bongy has quit ["Leaving"]
RobertFischer has joined #ocaml
ita has quit [Remote closed the connection]
rogo has joined #ocaml
evn_ has joined #ocaml
palomer has joined #ocaml
<palomer> http://www.lisperati.com/landoflisp/ <--silly comic on functional programming
<flux> I liked it. also the tehcnique how a large comic was brought to web was nice..
evn_ has quit [Read error: 104 (Connection reset by peer)]
evn_ has joined #ocaml
bla has quit [Read error: 110 (Connection timed out)]
bla has joined #ocaml
kopophex has joined #ocaml
Yoric[DT] has quit ["Ex-Chat"]
evn_ has quit []
pango_ has quit [Remote closed the connection]
bluestorm has joined #ocaml
pango_ has joined #ocaml
thelema has quit [Read error: 110 (Connection timed out)]
^authentic has joined #ocaml
evn has joined #ocaml
authentic has quit [Read error: 110 (Connection timed out)]
^authentic is now known as authentic
evn has left #ocaml []
munga has joined #ocaml
sporkmonger has quit []
munga has quit [Client Quit]
Linktim has joined #ocaml
Yoric[DT] has joined #ocaml
Linktim_ has joined #ocaml
kopophex has quit [Remote closed the connection]
Linktim has quit [Read error: 110 (Connection timed out)]
Linktim_ has quit [Read error: 110 (Connection timed out)]
thelema has joined #ocaml
bongy has joined #ocaml
Linktim has joined #ocaml
Linktim has quit [Remote closed the connection]
ita has joined #ocaml
jlouis has joined #ocaml
delamarche has joined #ocaml
OChameau has quit ["Leaving"]
olleolleolle has joined #ocaml
evn has joined #ocaml
<thelema> POLL: how fundamental is the concept of a string slice? Would you like a string library that does efficient slicing, but all operations are performed on slices?
<Yoric[DT]> What do you mean "all operations are performed on slices" ?
<thelema> for example, to get the index of a character, you need to give that function a slice
<thelema> (of course there'd be a simple function to convert a string to a substring)
<thelema> (substring = slice)
Snark has joined #ocaml
<thelema> This is in the context of immutable strings
<RobertFischer> thelema: Not very fundamental to me. If I was doing some kind of flat file parsing or something (basically, trying to make Ocaml do Perl's job), the story would be different.
<thelema> RobertFischer: should/could ocaml start encroaching on that part of the problem space?
<RobertFischer> thelema: Brian Hurt seems to think so (http://enfranchisedmind.com/blog/2006/05/06/ocaml-the-scripting-language/), but I'm not so sure. There's a lot of uphill work to get to be in Perl's space.
marmottine has joined #ocaml
<RobertFischer> The biggest part being a kind syntax around regular expressions.
Demitar has joined #ocaml
* thelema is tackling the Unicode part of the problem
<RobertFischer> And I'm not sure concepts like the global "$1", "$2", etc. variables are really ideas Ocaml should be picking up...but they're exactly what make Perl such a category killer language.
<thelema> (right now)
<thelema> RobertFischer: I think ocaml can do well with returning a tuple of matched substrings
<thelema> (when I program in perl, I try to avoid $1,$2 and use ($var1,var2...) = $str ~= /regex(part1)line-noise(part2)/
<Yoric[DT]> Have you looked at Martin Jambon's micmatch ?
<Yoric[DT]> It allows pattern-matching with regular-expressions, which is basically what we want.
<Yoric[DT]> Except we should extend that to streams.
* thelema is wary of any non-trivial camlp4
<RobertFischer> You can't return a tuple, because you don't know how many there will be.
<RobertFischer> You could return a list, but that's kinda noisy to decompose.
<thelema> well, I wouldn't want to implement perl5's regexes, perl6's rule/grammar constructs seem more useful
hkBst has quit ["Konversation terminated!"]
<thelema> maybe not all of what's specified, but that basic idea seems very workable.
schme has quit [Remote closed the connection]
<RobertFischer> thelema: Except that rules aren't nearly as seat-as-the-pants wonderful as regexps are.
<thelema> ? rules can contain arbitrary regexps
<thelema> grammar HTML {
<thelema> rule doc :iw { \Q[<HTML>] <?head> <?body> \Q[</HTML>] }
<thelema> rule head :iw { \Q[<HEAD>] <?head_tag>+ \Q[<HEAD>] }
<thelema> # etc.
<thelema> }
<RobertFischer> But they're nosiy.
^authentic has joined #ocaml
<RobertFischer> That's what's awesome about Regexps, even if Larry Wall (see http://enfranchisedmind.com/blog/2008/02/29/for-all-my-perl-peeps/larry-wall-haz-dem/, BTW) disagrees.
<thelema> so is some music - that doesn't keep some people from enjoying and others from hating.
evn has quit []
<RobertFischer> I totally agree. But I'm just telling you right now that if you want to take on Perl, your game is going to be golf.
<RobertFischer> (And http://enfranchisedmind.com/blog/2008/02/29/for-all-my-perl-peeps/ is the better link -- stupid comma.)
<thelema> feh. That's not a way to compete with perl - there's no contest.
<thelema> compete with perl by having strong, powerful types
<thelema> and producing code that works properly once it compiles
<RobertFischer> I'm not sure Perl's domain space is really helped with strong, powerful types.
<RobertFischer> Although it could do with having a more consistent type system: http://enfranchisedmind.com/blog/2005/10/19/a-defense-of-prototypes/
* RobertFischer is a recovering Perlhead (CHIA@CPAN, to be exact), and so has a lot of rants in this area, mostly cached on his blog.
* thelema made the (odd) transition from perl to ocaml, and still finds use for perl from time to time
alexyk has joined #ocaml
<RobertFischer> For quasiportable sysadmin stuff and string munging, it can't be beat. :)
<RobertFischer> I'd be interested to see what you come up with, though, if you decide to take it on.
<thelema> one thing at a time. Unicode is a nasty beast
<RobertFischer> Yeah, it is
<RobertFischer> Have fun with that.
olleolleolle has quit []
kelaouchi has joined #ocaml
palomer has quit [Read error: 110 (Connection timed out)]
authentic has quit [Read error: 110 (Connection timed out)]
^authentic is now known as authentic
ita has quit [Remote closed the connection]
psnively has joined #ocaml
alexyk has quit []
ikaros has quit ["segfault"]
bongy has quit ["Leaving"]
gene9 has joined #ocaml
RobertFischer has left #ocaml []
gene9 has quit [Client Quit]
Axioplase has joined #ocaml
alexyk has joined #ocaml
alexyk has quit [Client Quit]
Axioplase has quit [Client Quit]
alexyk has joined #ocaml
|Catch22| has joined #ocaml
ikaros has joined #ocaml
Axioplase has joined #ocaml
alexyk has quit [Read error: 110 (Connection timed out)]
ttamttam has joined #ocaml
ita has joined #ocaml
ygrek has quit [Remote closed the connection]
Ramzi has joined #ocaml
ygrek has joined #ocaml
ttamttam has left #ocaml []
<thelema> okay, I'm a beginner at large projects - I want to put some source files in my project into a subdir, I try to use -I to include that dir, but I still get Unbound value on values inside a file in that dir
mwc has joined #ocaml
ygrek has quit [Remote closed the connection]
coucou747 has quit ["bye ca veut dire tchao en anglais"]
psnively has quit []
Snark has quit ["Ex-Chat"]
coucou747 has joined #ocaml
psnively has joined #ocaml
delamarche has quit []
middayc has joined #ocaml
<ertai_> use ocamlbuild (ocamlbuild -I subdir1 -I subdir2 my_main.byte)
Morphous_ has quit [Read error: 110 (Connection timed out)]
Morphous_ has joined #ocaml
<thelema> I'm not able to change the build system of this project - it's pretty standard makefiles
<psnively> OCamlMakefile?
<thelema> psnively: no, Makefile.
<psnively> I meant, could you benefit from OCamlMakefile?
<psnively> Perhaps by inclusion into your Makefile?
<thelema> no, as I said, it's a large project with its own custom, complex build system. I'm messing with one part of it and want to put some code in a subdir.
<thelema> but still use that code in my changes to the project.
<thelema> maybe I could read an OCamlMakefile and see how they handle subdirs, but I imagine there's an easy answer that I'm just missing.
<psnively> OK. Good luck!
<ita> makefiles for a large project is a sign of fail
<psnively> == Try not to get saddled with make.
<thelema> heh. There's some progress in converting parts of this project to ocamlbuild, but I think this part will be stuck with make.
ikaros has quit ["segfault"]
marmottine has quit ["Quitte"]
bluestorm has quit ["Konversation terminated!"]
<Ramzi> I'm getting a char from a function called get_char which reads the next one from stdin.
<Ramzi> But I want to analyze it and do stuff with it.
<Ramzi> If I always just put get_char it'll return a different char. But if I save it, then I'm using a variable.
|Catch22| has quit [Read error: 104 (Connection reset by peer)]
<Ramzi> hmm, maybe i should read all of stdin into a string, and that way i can functionally refer to a letter by its unchanging position in the string.
<Smerdyakov> Ramzi, what's wrong with variables?
<Ramzi> The lesson is to learn functional programming by avoiding the use of imperative style.
<Smerdyakov> OCaml variables have nothing imperative about them.
Yoric[DT] has quit ["Ex-Chat"]
r0bby has quit [Remote closed the connection]
r0bby has joined #ocaml
ita has quit [Remote closed the connection]
Tetsuo has quit [Remote closed the connection]
hsuh has joined #ocaml
bzzbzz has joined #ocaml