Version française
Home     About     Download     Resources     Contact us    
Browse thread
Estimating the size of the ocaml community
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Oliver Bandel <oliver@f...>
Subject: Re: [Caml-list] Estimating the size of the ocaml community
On Fri, Feb 04, 2005 at 06:32:00PM +0100, sejourne_kevin wrote:
> Oliver Bandel a écrit :
> >9.: Pattern matching, that *really* is functional (seems to be necessary 
> >that it works
> >    like it is done in logical programming languages like Prolog or 
> >    similar?
> 
> Something like this could be fun (just like Prolog):
> 
> (*caml way*)
> let test = function
>     [(1,a);b;(3,c);(4,d)] ->Printf.printf "%d %d %d \n" a c d; b
>   | _ -> failwith "Unification Impossible"
> ;;
> (*half-prolog way*)
> let test [(1,a);b;(3,c);(4,d)] =  Printf.printf "%d %d %d \n" a c d; b
> and test _ = failwith "Unification Impossible"
> ;;

The second one ("half-prolog way") looks a littlebid like Haskell's
syntax.

What I mean is, that your

 (*caml way*)
 let test = function
     [(1,a);b;(3,c);(4,d)] ->Printf.printf "%d %d %d \n" a c d; b
   | _ -> failwith "Unification Impossible"
 ;;

would work equally for all input data, if written in the opposite order
of pattern-match code-lines:

 (*caml way*)
 let test = function
     _ -> failwith "Unification Impossible"
   | [(1,a);b;(3,c);(4,d)] ->Printf.printf "%d %d %d \n" a c d; b
 ;;

And this, because in a functional setting it does not matter,
which expression comes first: it's always the same result
for the same input data, independent of the order of lines of code.


Now (but in Haskell it's the same) it is NOT independent
of which comes first.

This was a mayjor problem of understanding Pattern Matches,
especially because all people said (in books and papers too!)
that pattern matching belongs to the functional world.

I now can use OCaml pattern matches without problems,
but in the first time I was very annoyed about saying
that this is a functional language feature, when it
really not is.

So, maybe the documentation and the papers and books
should not call it functional pattern matching, but
pattern matching (or imperative pattern matching).

As OCaml has in it's concept that it also uses OO-features and imperative
features, there is no problem for me to accept the
pattern matching features as they are now.
But I like it to say it, how it is (not, how people want to
show it, even if it is differently).

And IMHO such a lmatch (logical match) or fmatch (functional match)
should be added to the OCaml-Core. (If possible.)


[...]
> With a logic match, Ocaml could be functionnal, imperative, object and 
> logic.

Yes, that's fine. :)

I think only Oz can compete here (but as far as I know it
is not as efficient/performant as OCaml).


> Just need a dynamic syntax to have the power of Prolog with the 
> power of OCaml... cool. The problem with the logic
> match (* | "prefix"^str -> *) is that ^ isn't a constructor but a 
> function. I think, the logic match can't be determinist. IHMO, Prolog 
> can do it just because all data are term(s) as all 'function'.

Hmhhh, so you think there are theoretical problems to implement such thing?!


Ciao,
   Oliver