Version française
Home     About     Download     Resources     Contact us    
Browse thread
unused variable error with objects
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Julien Signoles <Julien.Signoles@l...>
Subject: Re: [Caml-list] unused variable error with objects

> With labeled functions, I usually do something like ~snoo:_, but it does not
> work in this exampled with methods:
> ---
> class foo = object
>  method bar ~(snoo : string):_ = ()
> end;;
>
> let biff = new foo;;
> biff#bar ~snoo:"hi";;
> --
> ocamlc -c -w Ae -warn-error Ae foo.ml
> File "foo.ml", line 2, characters 15-19:
> Warning Z: unused variable snoo.
>
> On a whim, I did the following, which surprisingly worked:
>
> class foo = object
>  method bar ~(_snoo : string) = ()
> end;;
>
> let biff = new foo;;
> biff#bar ~_snoo:"hi";;
>
> And that compiles, which confused me.  But I have to put the underbar into
> the method call, which seems wrong.
> Is there a solution to this?

Try this:

class foo = object
   method bar ~snoo:(_:string) = ()
end;;
(new foo)#bar ~snoo:"hi";;

--
Julien