Version française
Home     About     Download     Resources     Contact us    
Browse thread
surprising type error with labels
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jeremy Yallop <jeremy.yallop@e...>
Subject: Re: [Caml-list] surprising type error with labels
Jake Donham wrote:
> Why does
> 
>  ListLabels.find (fun _ -> true) [];;
> 
> produce
> 
>  Characters 16-31:
>    ListLabels.find (fun _ -> true) [];;
>                    ^^^^^^^^^^^^^^^
>  This expression should not be a function, the expected type is
>  ('a -> 'b) list
> 
> I thought the rule was that "if an application is total, labels may be
> omitted." (4.1 in the manual). (I was trying to do module List =
> ListLabels at the top of a file.) Thanks,

Applications of functions whose return types are type variables are 
never considered total, since it's possible to pass extra arguments if 
the type variable is instantiated to a function type.  For example, 
ListLabels.find has type

    f:('a -> bool) -> 'a list -> 'a

If the type variable is instantiated to `bool -> bool', say, then you 
can pass more than two arguments:

    ListLabels.find ~f:(fun f -> f false) [not] false

You can use the function without labels if you fix its return type:

    (ListLabels.find :  f:_ -> _ -> int) (fun _ -> true) []

Jeremy.