caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Re: [Caml-list] Haskell features in O'Caml
@ 2001-09-23 23:25 Arturo Borquez
  0 siblings, 0 replies; 12+ messages in thread
From: Arturo Borquez @ 2001-09-23 23:25 UTC (permalink / raw)
  To: florian; +Cc: caml-list

On Sun, 23 September 2001, Florian Hars wrote:

.....
> > > 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 +.

Yes, but default associativity can be overriden using
proper parens, and produces more readable code.

Best regards
Arturo 


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


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [Caml-list] Haskell features in O'Caml
  2001-09-24 22:51 Christian.Schaller
@ 2001-09-25  9:15 ` Remi VANICAT
  0 siblings, 0 replies; 12+ messages in thread
From: Remi VANICAT @ 2001-09-25  9:15 UTC (permalink / raw)
  To: caml-list

Christian.Schaller@cert.siemens.de writes:

> oops, yes you're right.  I was trying it that way:
> * create test.ml
> * compile it => test.cm[io] file
> * now create test.mli
> * compile test.ml again
> and no error message will be issued, since test.cmi is existing, though has
> totally different signature.  This problem does also occur whenever the
> interface is changing!  There seems to be no check if interface source is
> newer than the compiled one (I'm using OCaml 3.02 @ cygwin without tk;
> Win2k, English, SP2).

You should use make for check when source file are newer than compiled
one. 

> 
>   It gets also interesting, when you are using -i to see the signature of
> your definitions.  A correct test.mli will yield "val f : int -> int",
> however compiling the definition will yield "val f : 'a -> 'a".

it depend of what you want, int -> int is as correct as 'a -> 'a.

-- 
Rémi Vanicat
vanicat@labri.u-bordeaux.fr
http://dept-info.labri.u-bordeaux.fr/~vanicat
-------------------
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


^ permalink raw reply	[flat|nested] 12+ messages in thread

* RE: [Caml-list] Haskell features in O'Caml
@ 2001-09-24 22:51 Christian.Schaller
  2001-09-25  9:15 ` Remi VANICAT
  0 siblings, 1 reply; 12+ messages in thread
From: Christian.Schaller @ 2001-09-24 22:51 UTC (permalink / raw)
  To: caml-list

vanicat@labri.u-bordeaux.fr wrote:

> >   Since implementation is not automatically checked against 
> the interface
> > (or did I get something wrong?),
> 
> yes, you do:
> 
> test.ml :
> 
> let f x = x
> 
> test.mli :
> 
> val f : int -> float
> 
> $ ocamlc -c test.ml
> I/O error: test.cmi: No such file or directory
> $ ocamlc -c test.mli
> $ ocamlc -c test.ml
> The implementation test.ml does not match the interface test.cmi:
> Values do not match: val f : 'a -> 'a is not included in val 
> f : int -> float

oops, yes you're right.  I was trying it that way:
* create test.ml
* compile it => test.cm[io] file
* now create test.mli
* compile test.ml again
and no error message will be issued, since test.cmi is existing, though has
totally different signature.  This problem does also occur whenever the
interface is changing!  There seems to be no check if interface source is
newer than the compiled one (I'm using OCaml 3.02 @ cygwin without tk;
Win2k, English, SP2).

  It gets also interesting, when you are using -i to see the signature of
your definitions.  A correct test.mli will yield "val f : int -> int",
however compiling the definition will yield "val f : 'a -> 'a".

bye
  Chris...
-------------------
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


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [Caml-list] Haskell features in O'Caml
  2001-09-24 16:26 Christian.Schaller
@ 2001-09-24 19:53 ` Remi VANICAT
  0 siblings, 0 replies; 12+ messages in thread
From: Remi VANICAT @ 2001-09-24 19:53 UTC (permalink / raw)
  To: caml-list

Christian.Schaller@cert.siemens.de writes:

> > 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:
> > [...]
> > 
> 
>   Unfortunately there seems to be a difference between explicit module
> declaration as seen above and the separation of interface and
> implementation.
> 
>   Since implementation is not automatically checked against the interface
> (or did I get something wrong?),

yes, you do:

test.ml :

let f x = x

test.mli :

val f : int -> float

$ ocamlc -c test.ml
I/O error: test.cmi: No such file or directory
$ ocamlc -c test.mli
$ ocamlc -c test.ml
The implementation test.ml does not match the interface test.cmi:
Values do not match: val f : 'a -> 'a is not included in val f : int -> float



> you just load you implementation (or
> compile it) without using (or compiling) the appropriate interface and there
> will be no complaint about mismatch in signature and structure.
> 
>   I'd prefer the compiler/desktop automatically look for interface
> definition while compiling/loading.
> 
>   One more or less off-topic question about interfaces: is there a way to
> see the all what's inside a module when I'm opening it using "open" (like
> "module M : sig val mul : int -> int -> int end" in above example)?

yes :

$ Module T = List
module T :
  sig
    external length : string -> int = "%string_length"
    external get : string -> int -> char = "%string_safe_get"
    external set : string -> int -> char -> unit = "%string_safe_set"
[...]
    external unsafe_fill : string -> pos:int -> len:int -> char -> unit
      = "fill_string" "noalloc"
  end



-- 
Rémi Vanicat
vanicat@labri.u-bordeaux.fr
http://dept-info.labri.u-bordeaux.fr/~vanicat
-------------------
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


^ permalink raw reply	[flat|nested] 12+ messages in thread

* RE: [Caml-list] Haskell features in O'Caml
@ 2001-09-24 16:26 Christian.Schaller
  2001-09-24 19:53 ` Remi VANICAT
  0 siblings, 1 reply; 12+ messages in thread
From: Christian.Schaller @ 2001-09-24 16:26 UTC (permalink / raw)
  To: florian; +Cc: caml-list

> 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:
> [...]
> 

  Unfortunately there seems to be a difference between explicit module
declaration as seen above and the separation of interface and
implementation.

  Since implementation is not automatically checked against the interface
(or did I get something wrong?), you just load you implementation (or
compile it) without using (or compiling) the appropriate interface and there
will be no complaint about mismatch in signature and structure.

  I'd prefer the compiler/desktop automatically look for interface
definition while compiling/loading.

  One more or less off-topic question about interfaces: is there a way to
see the all what's inside a module when I'm opening it using "open" (like
"module M : sig val mul : int -> int -> int end" in above example)?

  Thanks a lot!!!

bye
  Chris...
-------------------
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


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [Caml-list] Haskell features in O'Caml
  2001-09-24 11:14     ` Sven
@ 2001-09-24 15:29       ` Brian Rogoff
  0 siblings, 0 replies; 12+ messages in thread
From: Brian Rogoff @ 2001-09-24 15:29 UTC (permalink / raw)
  To: Sven; +Cc: caml-list

On Mon, 24 Sep 2001, Sven wrote:
[...snip alternatives for type annotation in OCaml ...]
> But you have to recognize that non of these solution is as elegant as the
> haskel way of doing it, isn't ti ?

Agreed. Though the original poster probably wan't interested, it's also
the case that Haskell can use the annotations to get polymorphic recursion
and OCamlists have to butcher the code by either rewriting into a sometimes
less clear form or applying the sledge hammer of the unsafe cast operation.

> maybe this would be nice :
>
> val mul : int -> int -> int
> let mul x y = ...
>
> Sure, i know the right way is to put the declaration of mul in a separate
> file, but still, it would be nice to be able to do it in one file only.

I think it makes sense to have the annotations *apart* from their use in
signatures. Someone else mentions the "debugging by adding type annotations"
style, which I've used a bit myself (I'm shameless) and has a lot of nice
aspects.

-- Brian


-------------------
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


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [Caml-list] Haskell features in O'Caml
  2001-09-23 17:50   ` Dave Mason
@ 2001-09-24 11:14     ` Sven
  2001-09-24 15:29       ` Brian Rogoff
  0 siblings, 1 reply; 12+ messages in thread
From: Sven @ 2001-09-24 11:14 UTC (permalink / raw)
  To: Dave Mason; +Cc: Mattias Waldau, Arturo Borquez, steven, caml-list

On Sat, 22 Sep 2001 13:50:11 +0200, Steven Murdoch <steven@murdomedia.net> 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
>
On Sun, 23 Sep 2001 18:08:36 +0200, Florian Hars <florian@hars.de> wrote:
> # 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
>
On Sun, 23 Sep 2001 18:21:07 +0200, "Mattias Waldau" <mattias.waldau@abc.se> wrote: 
> # let mul (a:int) (b:int) : int = a*b;;
> val mul : int -> int -> int = <fun>
>
On Sun, Sep 23, 2001 at 01:50:21PM -0400, Dave Mason wrote:
> 
> # let (mul : int -> int -> int) = fun x y -> x*y;;
> val mul : int -> int -> int = <fun>
> 

But you have to recognize that non of these solution is as elegant as the
haskel way of doing it, isn't ti ?

maybe this would be nice :

val mul : int -> int -> int
let mul x y = ...

Sure, i know the right way is to put the declaration of mul in a separate
file, but still, it would be nice to be able to do it in one file only.

Friendly,

Sven Luthert
-------------------
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


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [Caml-list] Haskell features in O'Caml
  2001-09-23 16:21 ` Mattias Waldau
@ 2001-09-23 17:50   ` Dave Mason
  2001-09-24 11:14     ` Sven
  0 siblings, 1 reply; 12+ messages in thread
From: Dave Mason @ 2001-09-23 17:50 UTC (permalink / raw)
  To: Mattias Waldau; +Cc: Arturo Borquez, steven, caml-list

And you can do it like:

# let (mul : int -> int -> int) = fun x y -> x*y;;
val mul : int -> int -> int = <fun>

../Dave
-------------------
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


^ permalink raw reply	[flat|nested] 12+ messages in thread

* RE: [Caml-list] Haskell features in O'Caml
  2001-09-22 14:56 Arturo Borquez
  2001-09-23 16:08 ` Florian Hars
@ 2001-09-23 16:21 ` Mattias Waldau
  2001-09-23 17:50   ` Dave Mason
  1 sibling, 1 reply; 12+ messages in thread
From: Mattias Waldau @ 2001-09-23 16:21 UTC (permalink / raw)
  To: Arturo Borquez, steven; +Cc: caml-list

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 = <fun>
# let (&&&) (x:int) (y:int) : int = max x y;;
val ( &&& ) : int -> int -> int = <fun>
# 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 = <fun>
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 = <fun>
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 = <fun>
# 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


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [Caml-list] Haskell features in O'Caml
  2001-09-22 14:56 Arturo Borquez
@ 2001-09-23 16:08 ` Florian Hars
  2001-09-23 16:21 ` Mattias Waldau
  1 sibling, 0 replies; 12+ messages in thread
From: Florian Hars @ 2001-09-23 16:08 UTC (permalink / raw)
  To: Arturo Borquez; +Cc: steven, caml-list

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


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [Caml-list] Haskell features in O'Caml
@ 2001-09-22 14:56 Arturo Borquez
  2001-09-23 16:08 ` Florian Hars
  2001-09-23 16:21 ` Mattias Waldau
  0 siblings, 2 replies; 12+ messages in thread
From: Arturo Borquez @ 2001-09-22 14:56 UTC (permalink / raw)
  To: steven; +Cc: caml-list

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


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Caml-list] Haskell features in O'Caml
@ 2001-09-22 11:46 Steven Murdoch
  0 siblings, 0 replies; 12+ messages in thread
From: Steven Murdoch @ 2001-09-22 11:46 UTC (permalink / raw)
  To: caml-list

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.

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
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.


--
email: steven@murdomedia.net
web: http://www.murdomedia.net/
PGP/GnuPG keys: http://www.murdomedia.net/keys.html

-------------------
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


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2001-09-25  9:15 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-09-23 23:25 [Caml-list] Haskell features in O'Caml Arturo Borquez
  -- 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-22 14:56 Arturo Borquez
2001-09-23 16:08 ` Florian Hars
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
2001-09-22 11:46 Steven Murdoch

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).