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

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Eric C. Cooper <ecc@c...>
Subject: Re: [Caml-list] optional arguments and unification
On Tue, Jun 03, 2003 at 07:58:19PM -0700, Chris Hecker wrote:
> let f ?opt x = x + 1
> let g x = x + 1
> let h = if true then f else g
> 
> This expression has type int -> int but is here used with type
>   ?opt:'a -> int -> int
> 
> So you have to do this:
> 
> let h = if true then f ?opt:None else g

You could also write:
    let h = if true then (fun x -> f x) else g
or even
    let h = let f x = f x in if true then f else g

-- 
Eric C. Cooper          e c c @ c m u . e d u

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