* [Caml-list] 'b is unbound
@ 2004-05-12 6:31 briand
2004-05-12 11:43 ` Damien
0 siblings, 1 reply; 4+ messages in thread
From: briand @ 2004-05-12 6:31 UTC (permalink / raw)
To: caml-list
I'm getting the following error:
method op :
(float, 'a, 'b) Bigarray.Array2.t ->
float array -> float array -> unit
end
The method op has type
(float, 'a, 'b) Bigarray.Array2.t -> float array -> float array -> unit
where 'b is unbound
Is 'b really unbound, or is the inferencer simply unable to figure out
what the type should be ?
I tried explicitly setting the type for the first argument, but could
not create a type which would not give me some sort of error, e.g.
method op (j: (float, Bigarray.float64, Bigarray.c_layout) Bigarray.Array2.t) ...
gives me an error :
Unbound type constructor Bigarray.float64
Any help appreciated...
Brian
-------------------
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] 4+ messages in thread
* Re: [Caml-list] 'b is unbound
2004-05-12 6:31 [Caml-list] 'b is unbound briand
@ 2004-05-12 11:43 ` Damien
2004-05-12 19:11 ` briand
2004-05-13 2:54 ` briand
0 siblings, 2 replies; 4+ messages in thread
From: Damien @ 2004-05-12 11:43 UTC (permalink / raw)
To: caml-list
On Tue, 11 May 2004 23:31:48 -0700 briand@aracnet.com wrote:
> I'm getting the following error:
>
> method op :
> (float, 'a, 'b) Bigarray.Array2.t ->
> float array -> float array -> unit
> end
> The method op has type
> (float, 'a, 'b) Bigarray.Array2.t -> float array -> float array ->
> unit
> where 'b is unbound
>
> Is 'b really unbound, or is the inferencer simply unable to figure out
> what the type should be ?
polymorphic methods require to be explicitly typed
(this kind of type inference should lead to the one for system F)
# class o = object method id x = x end;;
Some type variables are unbound in this type:
class o : object method id : 'a -> 'a end
The method id has type 'a -> 'a where 'a is unbound
# class o = object method id: 'a.'a -> 'a = fun x -> x end;;
class o : object method id : 'a -> 'a end
# let o = new o in o#id 5, o#id "toto";;
- : int * string = (5, "toto")
or maybe you want the whole class to be parametrized wrt 'a :
# class ['a] o = object method id (x:'a) = x end;;
class ['a] o : object method id : 'a -> 'a end
# let o = new o in o#id 5, o#id "toto";;
This expression has type string but is here used with type int
hope this helps,
damien
-------------------
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] 4+ messages in thread
* Re: [Caml-list] 'b is unbound
2004-05-12 11:43 ` Damien
@ 2004-05-12 19:11 ` briand
2004-05-13 2:54 ` briand
1 sibling, 0 replies; 4+ messages in thread
From: briand @ 2004-05-12 19:11 UTC (permalink / raw)
To: Damien; +Cc: caml-list
>>>>> "Damien" == Damien <Damien.Pous@ens-lyon.fr> writes:
Damien> On Tue, 11 May 2004 23:31:48 -0700 briand@aracnet.com wrote:
>> I'm getting the following error:
>>
>> method op :
>> (float, 'a, 'b) Bigarray.Array2.t ->
>> float array -> float array -> unit
>> end
>> The method op has type
>> (float, 'a, 'b) Bigarray.Array2.t -> float array -> float array ->
>> unit
>> where 'b is unbound
>>
>> Is 'b really unbound, or is the inferencer simply unable to figure out
>> what the type should be ?
Damien> polymorphic methods require to be explicitly typed
Damien> (this kind of type inference should lead to the one for system F)
I'm not intending the method to be polymorphic.
op is simply a method which takes a Bigarray.Array2 type as an argument.
So it would seem that declaring the argument explicitly should solve
the problem.
Damien> # class o = object method id: 'a.'a -> 'a = fun x -> x end;;
Damien> class o : object method id : 'a -> 'a end
Damien> # let o = new o in o#id 5, o#id "toto";;
Damien> - : int * string = (5, "toto")
Here you are making the argument and return types consistent.
I believe that my problem is different.
It doesn't help that I don't understand what the problem is...
Brian
-------------------
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] 4+ messages in thread
* Re: [Caml-list] 'b is unbound
2004-05-12 11:43 ` Damien
2004-05-12 19:11 ` briand
@ 2004-05-13 2:54 ` briand
1 sibling, 0 replies; 4+ messages in thread
From: briand @ 2004-05-13 2:54 UTC (permalink / raw)
To: Damien; +Cc: caml-list
>>>>> "Damien" == Damien <Damien.Pous@ens-lyon.fr> writes:
Damien> polymorphic methods require to be explicitly typed (this
Damien> kind of type inference should lead to the one for system F)
After little more investigation I found that the following will work :
method op (j:(float, Bigarray.float64_elt, Bigarray.c_layout) Bigarray.Array2.t) f x =
Seems very straightforward. However there is one confusing aspect :
method op (j:(float, Bigarray.float64, Bigarray.c_layout) Bigarray.Array2.t) f x =
error -> Unbound type constructor Bigarray.float64
? Aha ! float64 in bigarray.mli is not a type but a val.
So now my method is no longer polymorphic, right ?
So everything makes sense until I go back to my bigarray test file :
let a = Bigarray.Array2.create Bigarray.float64 Bigarray.c_layout n n;;
is OK.
let a = Bigarray.Array2.create Bigarray.float64_elt Bigarray.c_layout n n;;
error -> Unbound value Bigarray.float64_elt
Then I looked at the definition for create and it finally makes sense.
However I would argue that it is also _very_ confusing.
Why doesn't create simply take the type, i.e. ..._elt instead of
('a, 'b) kind ??
Brian
-------------------
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] 4+ messages in thread
end of thread, other threads:[~2004-05-13 2:54 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-05-12 6:31 [Caml-list] 'b is unbound briand
2004-05-12 11:43 ` Damien
2004-05-12 19:11 ` briand
2004-05-13 2:54 ` briand
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox