caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] optional arguments and unification
@ 2003-06-04  2:58 Chris Hecker
  2003-06-04  3:23 ` Eric C. Cooper
  0 siblings, 1 reply; 2+ messages in thread
From: Chris Hecker @ 2003-06-04  2:58 UTC (permalink / raw)
  To: caml-list


I'm not sure I'm using the term "unification" properly, but here's the 
situation:

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

Which is kinda ugly and goes against the "spirit" of optional arguments, I 
think.  Would it be possible to have a rule that says "if two types need to 
be unified and the only thing standing in the way are unspecified optional 
arguments then the compiler will default them automatically"?  Or does that 
lead to something unsound?

Chris

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


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

* Re: [Caml-list] optional arguments and unification
  2003-06-04  2:58 [Caml-list] optional arguments and unification Chris Hecker
@ 2003-06-04  3:23 ` Eric C. Cooper
  0 siblings, 0 replies; 2+ messages in thread
From: Eric C. Cooper @ 2003-06-04  3:23 UTC (permalink / raw)
  To: caml-list

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


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

end of thread, other threads:[~2003-06-04  3:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-06-04  2:58 [Caml-list] optional arguments and unification Chris Hecker
2003-06-04  3:23 ` Eric C. Cooper

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