<bluestorm_>
because if your trivial case is in the "else", it may be too far from the original condition, and thus be forgotten
<bluestorm_>
furthermore, introducing recursivity with fib is a strange idea
<bluestorm_>
because this naive fibonacci implementation is terrible
<bluestorm_>
why not use factorial instead ?
<mrvn>
And don't use let rec foo x = if x ...
<mrvn>
let rec fix = function 0 -> 0 | 1 -> 1 | x -> fix (x - 1) + fib (x - 2)
<bluestorm_>
hm mrvn, maybe he didn't want to teach pattern matching at this point
<mrvn>
That mirrors the mathematical definition used for fib.
<bluestorm_>
if (n <= 1) is reasonably clear
<bluestorm_>
(and it handles the "negative n" case :-°)
<mrvn>
Maybe. I can't read the text, just code.
<bluestorm_>
so do i ^^
Z4rd0Z has quit []
johnnowak has joined #ocaml
<mrvn>
I would have expected an example of let rec fac x = if x <= 1 then 1 else x * fac (x-1)
jlouis has joined #ocaml
<bluestorm_>
hm
<bluestorm_>
let func a = a, "tekst";;
<bluestorm_>
maybe you should use (a, "tekst") first time
<mrvn>
bluestorm_: as example for recursion
<bluestorm_>
they may find it easier to read
<bluestorm_>
mrvn: i agree, fac seems a better example than fib
<mrvn>
Ahh, I agree with bluestorm_. Write tuples as (a, b). I still always do that for better readability.
<mrvn>
And add an example of fold_left
<bluestorm_>
i personally use "let a, b = ..." instead of "let (a, b) = ..."
<mrvn>
bluestorm_: too confusing to people used to int a, b = 1, c, d = 5;
<bluestorm_>
hm
<mrvn>
And I'm totaly missing type list = NIL | CONS of int * list
<mrvn>
followed by how you implement map and fold_left and then 'a list
<bluestorm_>
i agree
<bluestorm_>
assuming you're speaking to a general audience, i think the "functional programming" point of view should be emphasized
<mrvn>
And let a = fun(ction), match x with ...
<bluestorm_>
by introducing pattern matching sooner in the document, and doing more recursive things
david_koontz has joined #ocaml
<bluestorm_>
(working on list with map and fold_* are good brainwork for that)
<mrvn>
exactly.
<mrvn>
A good example for fold_left could be: # List.fold_left (+) 0 [1;2;3];;
<bluestorm_>
hm mrvn, but with this example, how will you explain the difference with fold_right ?
<mrvn>
Start off with List.fold_left (fun x acc -> x + acc) 0 [1;2;3] and then this shorter version
<mrvn>
bluestorm_: that you only see if you implement the two and explain tail recusion
<bluestorm_>
maybe there are easy applications where fold_right and fold_left give really different results
<bluestorm_>
hm
<mrvn>
That can be hard to understand and I would do that later. Beginers don't tend to have such big examles that fold_right fails.
<vorago>
bluestorm_, i've got it.
<bluestorm_>
yes, tail recursion isn't easy for a recursion beginner
<vorago>
mrvn, I was thinking of introducting matching later (it's in the last chapter, bot in written yet)
<mrvn>
I think matching is one of the major features for ocaml. The alternatives type makes it so powerfull.
<vorago>
I'll add factorial example.
<vorago>
It's good idea.
<vorago>
Probably next to fib, and then add some description after example.
<mrvn>
For fib you could show how one can transform the code to be tail recursive.
<vorago>
Ok, I'll add () around tuples with a comment where it can be omitted.
<vorago>
Hm..
<bluestorm_>
vorago:
<bluestorm_>
about fib
<bluestorm_>
it may be interesting to show a better implementation
<mrvn>
let fib x = let rec loop acc prev y = if y >= x then acc else loop (acc+prev) acc (y+1) in loop 1 1 1
<mrvn>
Shw how you write a function by first writing a helper and then call that.
<vorago>
As for type list = NIL | CONS of int * list I wanted to introduce variants in prelast chapter. Maybe it's wiser to do this earlier.
<mrvn>
vorago: It is the 4th thing the official manual teaches you.
<vorago>
I've got introduction a bit expanded. It goes like this: meeting with ocaml, how types are inferred, functions and general use of "let", tuples and arrays, records and references, how iterations are done, bigger ocaml example and variants.
<vorago>
I'll copy this talk somewhere and use it to slighthly rewrite this.
<mrvn>
functions as values/parameter/arguments is missing
<bluestorm_>
you could explain curryfication too
<bluestorm_>
let add = fun a -> fun b -> a + b;;
<mrvn>
People not familiar with functional languages won't know that you can just pass around fucntions like you would ints in C.
<vorago>
There's a comment for that, but I see no example.
<mrvn>
let inc = add 1
<bluestorm_>
vorago: it's useful to understand partial application
<bluestorm_>
hm
<bluestorm_>
or
<bluestorm_>
List.map (( + ) 2) [1; 2; 3];;
<mrvn>
and oppsoe that to let inc x = add 1 x
<vorago>
There's a "addfive" example.
<vorago>
let add a b = a+b;;
<vorago>
let addfive = add 5;;
<mrvn>
And do you have code that plays tic-tac-toe yet?
<vorago>
With quite big comment.
<mrvn>
Which reminds me. I always wanted to rewrite my self learning tic-tac-toe programm in ocaml.
<vorago>
Hm. (-;
<vorago>
I will move variants higher.
<vorago>
It's good idea.
<vorago>
Generally - I've got lot's of thing to do after this talk. Thanks.
<vorago>
It'd cool if I found somebody who speaks polish and knows OCaml. The problem is - there're few of us.
<mrvn>
You can make good examples with let color = GREEN | YELLOW | BLACK (simple enum), then add FOO of x, then lists, trees and such.
<mrvn>
Do you have a chapter on the module system and on classes?
<vorago>
I guess I be correcting this text forever. Wouldn't you split this text into two subpages?
<vorago>
I want to write about OO code in OCaml, and module system, but not yet.
<mrvn>
Good look and have fun.
<vorago>
I'll at least write that there's sth like this with link too some more documentation.
nuncanada has quit ["Leaving"]
<mrvn>
and don't forget exceptions
<vorago>
There's a single exception in the last/bigger example.
<vorago>
With comment that it uses matching to handle them...
<vorago>
I need to place this matching+variants earlier.
<vorago>
Okay; Thanks mrvn and thanks bluestorm_.
<vorago>
Cya.
mbishop has quit ["Leaving"]
bluestorm_ has quit ["Konversation terminated!"]
fezsentido has joined #ocaml
fezsentido has quit [Read error: 104 (Connection reset by peer)]
nuncanada has joined #ocaml
_JusSx_ has quit ["leaving"]
smimou has quit ["bli"]
cjeris has quit [Read error: 104 (Connection reset by peer)]
JeffSmac has joined #ocaml
<JeffSmac>
hello. is anyone here proficient with labltk programming?