Version française
Home     About     Download     Resources     Contact us    
Browse thread
generic functions
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Olivier Andrieu <andrieu@i...>
Subject: Re: [Caml-list] generic functions
 Alex Baretta [Mon, 10 Jan 2005]:
 > 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

Hum, I would have written this in that way :
,----
| let foo_int   (`Int x)   = `Int   (x * x)
| let foo_float (`Float x) = `Float (x *. x)
| 
| let foo = function
|   | #poly_int   as x -> foo_int x
|   | #poly_float as x -> foo_float x
`----

What's the use for the `other -> foo other' clauses ?

-- 
   Olivier