<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.