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 SAA25069; Sun, 23 Sep 2001 18:21:39 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id SAA25065 for ; Sun, 23 Sep 2001 18:21:38 +0200 (MET DST) Received: from mailc.telia.com (mailc.telia.com [194.22.190.4]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id f8NGLcn23166 for ; Sun, 23 Sep 2001 18:21:38 +0200 (MET DST) Received: from d1o849.telia.com (d1o849.telia.com [213.66.248.241]) by mailc.telia.com (8.11.6/8.11.6) with ESMTP id f8NGLY117131; Sun, 23 Sep 2001 18:21:34 +0200 (CEST) Received: from gateway (h40n2fls34o849.telia.com [217.208.235.40]) by d1o849.telia.com (8.10.2/8.10.1) with SMTP id f8NGL3a03065; Sun, 23 Sep 2001 18:21:03 +0200 (CEST) From: "Mattias Waldau" To: "Arturo Borquez" , Cc: Subject: RE: [Caml-list] Haskell features in O'Caml Date: Sun, 23 Sep 2001 18:21:07 +0200 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2911.0) Importance: Normal X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2526.0000 In-Reply-To: <20010922145636.16402.cpmta@c012.sfo.cp.net> Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk You can also write the resulting type of the function. I also explicitely type many of my functions in order to find bugs. # let mul (a:int) (b:int) : int = a*b;; val mul : int -> int -> int = # let (&&&) (x:int) (y:int) : int = max x y;; val ( &&& ) : int -> int -> int = # 2 &&& 3;; - : int = 3 /mattias -----Original Message----- From: owner-caml-list@pauillac.inria.fr [mailto:owner-caml-list@pauillac.inria.fr]On Behalf Of Arturo Borquez Sent: Saturday, September 22, 2001 4:57 PM To: steven@murdomedia.net Cc: caml-list@inria.fr Subject: Re: [Caml-list] Haskell features in O'Caml On Sat, 22 September 2001, Steven Murdoch wrote: > > I've been using Haskell a little for the past year or so and I like > quite a few of it's features, more recently I thought I'd look into > O'Caml and I've been impressed by it's speed and versatility but I was > wondering if it had some features found in Haskell. > > 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 > The Haskell compiler will deduce the type of mul from the second line > in a similar way to O'Caml and if it does not match the first line an > error is raised. Ocaml: # let mul a b = a * b;; val mul : int -> int -> int = As Ocaml is strong typed function mul is resolved to be an integer function (denoted by operator * only valid to integers). # let mul (a:int) (b:int) = a * b;; val mul : int -> int -> int = same result as above but here integer type is explicitly annotated. As Ocaml do not do implicit data type coercions the compliler checks that arguments passed to mul function must be allways of integer type. So your concerns with 'pure' Ocaml code will never occur, because compiler will catch these issues. The only way to cheat compiler is to provide mul as an external 'C' function that return other type during run-time. For run-time debugging Ocaml also provide assertion checking (see documentation chapter 7.3) > > I find that this catches a lot of my mistakes and it would be great if > O'Caml has a similar way to check whether the implied type of a > function matches (or is a subtype of) an explicit definition. > > Another feature I would like is whether it is possible to define > custom operators that can be put between it's operands rather than in > front of them. 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. > Also if a function is named using operator symbols it can be used as > an operator, e.g if &&& is defined as: > (&&&) :: Int -> Int -> Int > x &&& y = max x y > then "2 &&& 3" will return 3 Ocaml: # let ( &&& ) x y = if x >= y then x else y;; val ( &&& ) : 'a -> 'a -> 'a = # 3 &&& 5;; - : int 5 > This can lead to some very easy to read programs so I would like to > know if either or both of these ways of defining operators has a > equivalent in O'Caml. > > Thanks in advance, > Steven Murdoch. > > So I think that your needs are yet fullfilled in actual Ocaml implementation. Best regards Arturo Borquez Find the best deals on the web at AltaVista Shopping! http://www.shopping.altavista.com ------------------- 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 ------------------- 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