Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] mystified by typing of optional arguments
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jacques Carette <carette@m...>
Subject: RE: [Caml-list] mystified by typing of optional arguments
This can be simplified further:

let f ?opt x =
     match opt with
     | None -> x
     | Some dx -> x + dx

let g x = x + 1

Then (in ocaml 3.06)

# [f;g];;
Characters 3-4:
  [f;g];;
     ^
This expression has type int -> int but is here used with type
  ?opt:int -> int -> int
# [g;f];;
- : (int -> int) list = [<fun>; <fun>]

In other words it looks like unification of optional types is not
commutative !  This is indeed surprising.  I can understand that this could
simplify implementation, but is there a theoretical reason that underlies
this ?

Jacques

-----Original Message-----
From: owner-caml-list@pauillac.inria.fr
[mailto:owner-caml-list@pauillac.inria.fr] On Behalf Of Francois Rouaix
Sent: April 3, 2003 9:51 AM
To: caml-list@inria.fr
Subject: [Caml-list] mystified by typing of optional arguments 


Hi all,
The following example mystifies me

let f ?opt x =
   match opt with
   | None -> x
   | Some dx -> x + dx

let g x = x + 1


let h1 = function
   | 0 -> [g]
   | _ -> [f; g]


let h2 = function
   | _ -> [f; g]


h1 is typable but not h2.
Why is that ?

--f
PS: the example code is not meant to be useful in any way other than 
reproducing the behavior of type checking.

-------------------
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/ Beginner's list:
http://groups.yahoo.com/group/ocaml_beginners

-------------------
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/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners