ocaml pattern match question -


I am trying to write a simple recursive function which returns the list and returns a pair of integers it is C / Easy to write in C ++ / Java, but I would like to type the conflict

It goes to cause the OCaml solution to detect the solution so that somehow new to the new kind.

  REC test pl = ... ;; Val Differently: ('a -> bool) - & gt; 'A list - & gt; Int * int = & lt; Funny & gt; Test (fun x -> x mod 2 = 0) [-3; 5; 2; -6] ;; -> int * integer = (2, 2)  

So problem how can I return the value to recursively Tupl ..

has been removed from OCaml for a bit, but I think the comment in this comment

  relates to details of REALFREE Will go to Rick Test l = match L [] - & gt; (0,0) | X :: xs - & gt; If X & gt; 0 then with (x, y) (test xs) - & gt; Match (X + 1, Y) from second match (Test X) (X, Y) - & gt; (X, Y + 1) ;;  

You used nested match statements to exit the pieces of tuple

Edit can modify: I syntax Pascal Cuoq in his comment It was not known about the mentioned below, here is the code, it is a little lower and lower:

  REC test l = with match l [] -> (0,0) | X :: xs - & gt; If X & gt; 0 So let's (x, y) = test in x (x + 1, y) and let's (x, y) = test in xs (x, y + 1) ;;  

But the accepted answer is still very good, especially with tail recapitulation;).


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -