sponge45 changed the topic of #ocaml to: Discussions about the OCaml programming language | http://caml.inria.fr/
swater has quit ["Quat"]
jeffs has quit ["Quit"]
pbx has joined #ocaml
smimou has quit ["bli"]
pbx has left #ocaml []
david_koontz has joined #ocaml
bohanlon has quit [Remote closed the connection]
bohanlon` has quit [Remote closed the connection]
vorago has quit [Connection timed out]
malc_ has quit ["leaving"]
hs has joined #ocaml
<hs> hello again
<hs> i have a very simple question: how do i apply a function to a function ?
<hs> i'm still having some syntax problems
<hs> say :
<hs> let sum3 n = n + 3 ;;
<hs> let res = sum3 sum3 0 ;;
<hs>
<hs> it's missing a ;
<Smerdyakov> And the problem is what?
<hs> the example is not so good, i have put some parenthesis and it works now
<Smerdyakov> I'm pretty sure your example parses.
<hs> nop
<Smerdyakov> It does for me.
<hs> i get
<Smerdyakov> Perhaps you misinterpret a type-checking error as a parse error.
<hs> # Characters 10-14:
<hs> let res = sum3 sum3 0;;
<hs> ^^^^
<hs> This function is applied to too many arguments,
<hs> maybe you forgot a `;'
<Smerdyakov> Yup, that's a type-checking error.
<hs> #
<hs> oh, ok....
<hs> true... i have to get used to it.. sry
david_koontz has quit ["This computer has gone to sleep"]
pstickne has quit [Connection reset by peer]
pstickne has joined #ocaml
hs is now known as southbr
<southbr> so... let's try again
<southbr> i have this function
<southbr> process_file (print_list (string_split)) "teste.txt" ;;
<southbr>
<southbr> process_file applies some function to each line of the read text file
<southbr> but i want to pass not a simple function, but something like that (print_list (string_split))
<southbr> I think i need something like a lambda to construct a function in place
<Smerdyakov> If print_list (string_split) has the right type, then it's fine to use just as you have.
<southbr> something like process_file (lambda (x) (print_list (string_split x))) but i don't know how to do something like that in ocaml
<Smerdyakov> I see. A composition operator would do nicely, but OCaml has none in the standard library.
<Smerdyakov> For how to write anonymous functions, consult the manual.
<Smerdyakov> It's pretty clear you've done minimal reading about OCaml if you don't know the form, so you would benefit from reading the whole manual tutorial through before proceeding.
<southbr> ok, it's just that i have some assignments and i want to tackle them with ocaml instead of c :)
<southbr> i wont bother you again
<southbr> thanks
southbr has quit ["RTFM"]
ircleuser has joined #ocaml
Smerdyakov has quit ["Leaving"]
<ircleuser> if anyone could help me figure out where to put "lazy" and "Lazy.force" in "let fib = let rec aux a b = (a+b)::(aux b (a+b)) in aux 0 1" to make it work without a stack overflow, I'd appreciate it.
ircleuser is now known as jeffs
<jeffs> doh, dumb default name
<jeffs> actually
<jeffs> let fib = let rec aux a b = a::(aux b (a+b)) in aux 0 1
david_koontz has joined #ocaml
<jeffs> hi
joshcryer has joined #ocaml
<Mr_Awesome> jeffs: im stumped. this damn type system keeps preventing me from doing it the way i do it in lisp :(
<jeffs> ya I don't know either
<jeffs> I've tried every combination I could think of.
<jeffs> You'd think it'd be something not too hard, considering it's built into the language.
<jeffs> Thanks for trying, though!
<Mr_Awesome> i think ive come up with a solution
<Mr_Awesome> if you define a type like "type 'a lazy_list = Cons of 'a * 'a lazy_list Lazy.t | Nil"
<jeffs> I was just hoping there was an easier way :\
joshcryer has quit [Nick collision from services.]
<Mr_Awesome> jeffs: i see. since someone else has independently come up with that, id say its the only solution
<Mr_Awesome> in lisp, the same thing applies basically. there is a different type for a lazy list, called a "stream"
<Mr_Awesome> ocaml also has native support for streams i thought
<jeffs> it does. you can use streams for lazy evaluation
<jeffs> I was hoping to do it in a more Haskell-esque way using the lazy keyword. Oh well.
<Mr_Awesome> haskell has a better way to do it?
<jeffs> I mean, (let fib = let rec aux a b = a::(aux b (a+b)) in aux 0 1) looks so natural
<jeffs> Ya, as far as I know, in haskell you can do something like "List.hd (let fib = let rec aux a b = a::(aux b (a+b)) in aux 0 1)" and it doesn't complain.
<jeffs> It only calculates the list "fib" as far as you ask it, whereas caml wants to produce an infinite list right away.
<Mr_Awesome> oh duh, haskell is lazy by default
<jeffs> ya...
<jeffs> so I was thinking that just using "lazy" and "Lazy.force" would turn on ocaml's laziness somehow, making it act just like haskell.
<Mr_Awesome> well in a way it does, you just have to jump through a few hoops
<Mr_Awesome> like making a new type
<jeffs> Ya... oh well.
jeffs has quit ["Quit"]
jeffs has joined #ocaml
shawn has left #ocaml []
slipstream-- has joined #ocaml
slipstream has quit [Read error: 110 (Connection timed out)]
diffbavis has joined #ocaml
<pango_> let fib =
<pango_> let rec aux a b = [< '(a+b); aux b (a+b) >] in
<pango_> aux 0 1
<pango_> main 'problem' with ocaml's streams is that reads are destructive
<pango_> let rec stream_read n = parser
<pango_> | [< 'i; str >] -> if n > 0 then i :: stream_read (n-1) str else []
<pango_> # stream_read 10 fib ;;
<pango_> - : int list = [1; 2; 3; 5; 8; 13; 21; 34; 55; 89]
<pango_> # stream_read 10 fib ;;
<pango_> - : int list = [233; 377; 610; 987; 1597; 2584; 4181; 6765; 10946; 17711]
<pango_> (mmh this stream_read sucks, it loses one element... but you get the idea)
johnnowak has joined #ocaml
johnnowak has quit [Client Quit]
<jeffs> That's a good try, pango.
<jeffs> like you said though, it's still not quite like Haskell. I would want to do something like List.hd (Lazy.force fib) and that should always give 0. Like Mr. Awesome said, to do this in ocaml we probably have no choice but to define a lazy list type.
<pango_> yes, because :: is 'a -> 'a list -> 'a list, and you want to bundle non lazy and lazy value types, so standard lists cannot be used
jeffs has quit [Read error: 110 (Connection timed out)]
johnnowak has joined #ocaml
johnnowak has quit [Client Quit]
johnnowak has joined #ocaml
<flux-> do you guys think it'd be difficult to have ocaml compiler create a 'value tag list', which would construct a file that would indicate, for any value in the source, where it is defined? it could be used for example intelligent search/replace symbol name (all the symbols would have the same definition location)
<flux-> similarly for types, modules, I suppose
<flux-> maybe it'd help with the search and replace if I just told xemacs that ' isn't a word separator :)
<pango_> doesn't otags do something similar already ?
<flux-> I think it only lists top-level definitions?
<flux-> but I suppose it could be altered
<flux-> but it's not easy to see from the preprocessor, to which symbol does 'a' in the source code refer to
<flux-> and otags uses the camlp4-mechanism, right?
<pango_> afair, yes, it uses camlp4
Mr_Awesome has quit ["...and the Awesome level drops"]
david_koontz has quit ["Leaving"]
dark_light has quit [Remote closed the connection]
johnnowak has quit []
ikaros_ has quit ["segfault"]
ikaros_ has joined #ocaml
smimou has joined #ocaml
johnnowak has joined #ocaml
johnnowak has quit []
johnnowak has joined #ocaml
vorago has joined #ocaml
bebui has quit [Read error: 110 (Connection timed out)]
bebui has joined #ocaml
bluestorm_ has joined #ocaml
swater has joined #ocaml
johnnowak has quit []
descender has joined #ocaml
dark_light has joined #ocaml
diffbavis has quit [Read error: 104 (Connection reset by peer)]
Smerdyakov has joined #ocaml
diffbavis has joined #ocaml
_JusSx_ has joined #ocaml
jeffs has joined #ocaml
pango_ has quit [Remote closed the connection]
mikeX has joined #ocaml
benny_ has joined #ocaml
benny has quit [Read error: 145 (Connection timed out)]
malc_ has joined #ocaml
pango has joined #ocaml
Mr_Awesome has joined #ocaml
<jeffs> hi again mr pango and awesome. I'm working lazy lists still :)
slipstream-- has quit [Read error: 104 (Connection reset by peer)]
slipstream has joined #ocaml
pango has quit [Remote closed the connection]
<jeffs> some of the functions are dangerous...
<jeffs> for isntance, "Lazylist.exists (fun a -> a=84295) fib" might never return a value
<jeffs> where fib is a lazy list of the entire fibonacci sequence
<bluestorm_> hmm
<bluestorm_> lazy list is something i one day was interested in
<bluestorm_> could i see the code ?
<jeffs> sure
<jeffs> I'll publish it on my blog that I made recently just for publishing my ocaml projects.
<jeffs> when I'm done
pango has joined #ocaml
<bluestorm_> (what's your blog url ?)
pango_ has joined #ocaml
slipstream has quit [Success]
slipstream has joined #ocaml
<jeffs> it's pretty new, so there's not much there
<jeffs> and I wish it would post each day in reverse chronological order.
<jeffs> the posts in each day that is
postalchris has joined #ocaml
<Mr_Awesome> interesting
ikaros_ has quit [Read error: 110 (Connection timed out)]
ikaros_ has joined #ocaml
swater has quit ["Quat"]
pantsd has joined #ocaml
<jeffs> ok I published the lazylist library I wrote
<jeffs> bbl
postalchris has quit [Read error: 113 (No route to host)]
<mbishop> Can anyone tell me what's wrong with this? http://paste.lisp.org/display/38327
<jeffs> I added a few functions for converting to and from other data types, such as regular lists
<mbishop> It compiles fine, but it doesn't work for the keypress
<mbishop> it's supposed to call run_cb when "Enter" is pressed...but it doesn't heh
<mbishop> no warnings, no errors, just doesn't seem to work
<jeffs> no idea, but I never coded much in the way of GUIs in ocaml
malc__ has joined #ocaml
<mbishop> but malc__ probably has :P
<mbishop> malc__: can you take a look at http://paste.lisp.org/display/38327 and tell me why pressing Enter doesn't do what it's supposed to?
<Mr_Awesome> where exactly does it fail to meet your expectations?
<mbishop> Pressing Enter should call run_cb, same as pressing "Run", however it just...doesn't heh
<Mr_Awesome> does run_cb ever get called? does keypress ever get called?
<mbishop> I have no idea, should I check by debugging?
<Mr_Awesome> you can debug, or you could even just print stuff at various points
<mbishop> yeah I just put in a print line inside the keypress function, and it doesn't print
postalchris has joined #ocaml
<Mr_Awesome> then you have likely set up the GUI callbacks incorrectly
postalchris has quit [Client Quit]
<Mr_Awesome> perhaps there is something set within the GUI that is preventing you from receiving keypresses
<Mr_Awesome> if you have code that works, id suggest comparing it to your current code to find out where you went wrong
malc_ has quit [Read error: 110 (Connection timed out)]
<mbishop> Hmm, I'm still not sure why it isn't running the callback
<malc__> mbishop: sigh
<malc__> mbishop: you are partially applying
<malc__> button#connect#clicked ~callback:(run_cb input);
<malc__> add () or something
<malc__> -warn-error A is your friend
<mbishop> malc__: well that part actually runs fine
<mbishop> it's the keypress function that doesn't seem to work
<mbishop> Ahh, I figured it out
<jeffs> excellent
<mbishop> it's GdkKeysyms._Return instead of GdkKeysyms._KP_Enter
<malc__> and that should teach you another important lesson
<malc__> which is: always flush your channels
<malc__> and sorry for the wrong "hint"
<mbishop> Heh, what does that mean?
<malc__> you said that printing something inside the callback didn't work
<malc__> io channels in ocaml are buffered
<malc__> unless flushed nothing would indeed be printed
<mbishop> oh, right
_JusSx_ has quit [Client Quit]
bluestorm_ has quit ["Konversation terminated!"]
love-pingoo has joined #ocaml
johnnowak has joined #ocaml