caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Alex Baretta <alex@barettadeit.com>
To: Ocaml <caml-list@inria.fr>, Paolo Donadeo <paolo@barettadeit.com>
Subject: Re: [Caml-list] generic functions
Date: Mon, 10 Jan 2005 10:55:34 +0100	[thread overview]
Message-ID: <41E25116.1010805@barettadeit.com> (raw)
In-Reply-To: <Pine.LNX.4.44.0501090907240.5563-100000@localhost.localdomain>

Brian Hurt wrote:
> On Sun, 9 Jan 2005 wiedergaenger@fastmail.fm wrote:
>
>>let foo (x : int) = x*x;;
>>let foo (x : float) = x*.x;;
>>

> With the exception of certain artificial contests (Paul Graham) I've never 
> met a real world problem that needed overloading, or even benefitted 
> signifigantly from overloading that didn't benefit just as much or more 
> from one of the solutions above.
> 
> Brian

As a member of the International Caml's Jihad, I'd like to spend two 
cents of dynamite on this topic: type inference is as good as honey in 
large scale industrial projects, where sometimes the typing of complex 
recursive polymorphic algorithms is not evident until you get the 
printout from the compiler or the toplevel. Thank you, O great 
Unification Algorithm.

But, then again, extensional polymorphism is also a much needed feature. 
In my company we depend heavily on on extensional polymorphism to create 
exstensibile functions. We have implemented this on top of explicitly 
polymorphic types: i.e. polymorphic variant types.

Let us all faithfully await the Coming of the the Gcaml... And meanwhile 
let us use polymorphic variants to get the same effect.

type poly_int = [ `Int of int ]
type poly_float = [ `Float of float ]

let foo_int foo = function
   | `Int x -> `Int(x * x)
   | other -> foo other

let foo_float foo = function
   | `Float x -> `Float(x *. x)
   | other -> foo other

let rec foo x = match x with
   | #poly_int -> foo_int foo x
   | #poly_float -> foo_float foo x


All hail Ocaml!

Alex, after too many nights spent writing typechecking code...

-- 
*********************************************************************
http://www.barettadeit.com/
Baretta DE&IT
A division of Baretta SRL

tel. +39 02 370 111 55
fax. +39 02 370 111 54

Our technology:

The Application System/Xcaml (AS/Xcaml)
<http://www.asxcaml.org/>

The FreerP Project
<http://www.freerp.org/>


  parent reply	other threads:[~2005-01-10  9:55 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-01-09 13:19 wiedergaenger
2005-01-09 14:56 ` [Caml-list] " Richard Jones
2005-01-09 15:48 ` Brian Hurt
2005-01-09 17:17   ` David McClain
2005-01-09 18:09     ` brogoff
2005-01-09 18:45   ` padiolea
2005-01-10  0:23   ` skaller
2005-01-11 12:14     ` Daniel Yokomizo
2005-01-10  9:55   ` Alex Baretta [this message]
2005-01-10 10:47     ` [Caml-list] " Olivier Andrieu
2005-01-10 12:16       ` Alex Baretta
2005-01-12 23:49     ` Aleksey Nogin

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=41E25116.1010805@barettadeit.com \
    --to=alex@barettadeit.com \
    --cc=caml-list@inria.fr \
    --cc=paolo@barettadeit.com \
    /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).