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

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jacques Garrigue <garrigue@k...>
Subject: Re: [Caml-list] Typing of default arguments
From: Patrick M Doane <patrick@watson.org>

> Any thoughts about the restriction of polymorphism that can happen when
> using default arguments? It is still annoying that d' fails to type-check.
> 
> I would assume that the function could be type-checked as if the default
> argument did not exist, and then type-check the default value against the
> signature of the function for consistency.
> 
> This strategy would then give f and f' these types:
> 
>    val f  :  g:('a -> 'b) -> 'a -> 'b
>    val f' : ?g:('a -> 'b) -> 'a -> 'b

Since the default value for g is (fun x -> x), when g is omitted 'a =
'b should be enforced.
Otherwise, (fun x -> f' x) would be of the magic type ('a -> 'b),
which is certainly not what you are asking for.
Enforcing such a conditional equation is possible, but this would
means yet another extension to the type system:

    val f' : ?g:('a -> 'b ?= 'c -> 'c) -> 'a -> 'b

meaning that the default value for g has type 'c -> 'c.
Two problems: is it really worth it (you are not the first one to ask
for that, but would this improve a lot programming style?), and what
are the consequences. In particular it would probably mean more
polymorphic types at places where you do not really need them,
requiring more type annotations to make them readable.

    Jacques
-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr