Zadeh has quit [Read error: 104 (Connection reset by peer)]
<Vincenz>
it complains on line 11
<Vincenz>
inside the function
<Vincenz>
ah, you can't have functions with more than one param?
<Vincenz>
how would I solve that then?
<Vincenz>
(I mean, how do I make a nameless function that accepts two params without resorting to 'function a -> function b')
<Vincenz>
got it, it's 'fun'
<Vincenz>
how do I type a function?
<mellum>
vincez: let f x: int->int = succ
<Vincenz>
aha, thnx
<Vincenz>
what if I have
<Vincenz>
let f x = function
<mellum>
vincenz: but there is rarely a reason to do that
<Vincenz>
| ..y...stuff.. ->
<Vincenz>
mellum; why? I think if I restrict my types it clarifies the usage
<mellum>
If the program is that complicated, you usually create an .mli file that contains function signatures
<mellum>
Also, types can sometimes get pretty verbose
<Vincenz>
ah, i see
<mellum>
Hm, the best I have in my program is val edge_fold : (Graph.graph -> int -> int -> bool) -> ('a -> Branch.obj -> 'a) -> 'a -> Graph.graph -> 'a :-)
<Vincenz>
what's it do?
<Vincenz>
like a list fold but for graphs?
<Vincenz>
I'm trying to study this compiler book on my own
<Vincenz>
I'm at chapter 1
<Vincenz>
straightline interpreter :)
<mellum>
It's actually not that complicated, it's like list.fold, only it takes an additional filter, and iterates over edges of a graph
<Vincenz>
I followed the course last year, but it was in based on a C book, and we didn't get much practice. So I ordered the same book but the ML version and I'm trying to do it all now :)
<Vincenz>
hmm
<Vincenz>
how do I get the last element of a list?
<mellum>
You don't, since that is an expensive operation :)
<Vincenz>
I have to
<Vincenz>
I've got a list of expressions
<Vincenz>
each has to be executed and I want the value from the last
<Vincenz>
but since the other ones might have sideeffects..
<Vincenz>
hmm
<Vincenz>
perhaps a list.fold_right
<mellum>
Sounds like a job for fold.
<Vincenz>
fold_left or right?
<mellum>
Uh, I always confuse those two...
<Vincenz>
yeah, me too
<Vincenz>
I want the head to be executed first
<Vincenz>
heh
<Vincenz>
easy to test
<Vincenz>
just use a ref
<Vincenz>
ah!
<Vincenz>
List.fold_left
<Vincenz>
List.fold_left (fun r v-> r:=v;r) a [1; 2; 3];;
<Vincenz>
List.fold_right (fun v r-> r:=v;r) [1; 2; 3] a;;
<Vincenz>
:)
<Vincenz>
fold_left gives me a {contents = 3}
<Vincenz>
fold_right gives me a {contents = 1}
<Vincenz>
:))
<Vincenz>
almost done with my first interpreter
<Vincenz>
I'll put it on nopaste if you want to see it
<mellum>
What does it interpret?
<Vincenz>
this custom code that they use as an example
<Vincenz>
it's just chapter 1
<Vincenz>
an intro
<Vincenz>
but I want to do everything in this book
* Vincenz
is at page 11 of 520
<mellum>
You got a lot of time? :)
<Vincenz>
nope
<Vincenz>
I work
<Vincenz>
but not this week anymore
<Vincenz>
vacation until sunday
<Vincenz>
hmm
<Vincenz>
could you help me with a fold statement?
<mellum>
maybe
<Vincenz>
ok
<Vincenz>
as output I want a pair (int, list)
<Vincenz>
where the list is a lookuptable (don't worry about the construction of that)
Kinners has joined #ocaml
<Vincenz>
as input I have a list of expressions
<Vincenz>
and I have the function
<Vincenz>
interpExp : expression -> list -> (int, list)
<Vincenz>
where this list is a lookuptable too
<Vincenz>
ah, I might have it :)
<Vincenz>
List.fold_right (fun v r-> r:=v;r) [1; 2; 3] a;;
<Vincenz>
shit
<Vincenz>
let (n2, l2) = List.fold_left (fun (n1, l1) e -> interpExp e l) (0, l) l
<Vincenz>
heh
<Vincenz>
of course...I finish programming and I have errors
<Vincenz>
Yay!
<Vincenz>
Wahoo, it works :)
<Vincenz>
want me to paste it online?
<mellum>
Vincenz: Well, then just quickly write an optimizing C++ compiler, and it is enough for today ;)