List Info

Thread: "ocaml_beginners"::[] The type of this expression... contains type variables that cannot be generali




"ocaml_beginners"::[] The type of this expression... contains type variables that cannot be generali
user name
2006-12-31 04:36:29

On Sunday 31 December 2006 03:38, Grant Olson wrote:
> I'm trying to create a hashtable with keys that are strings, and values
> that are OpenGL textures from the lablgl package. I get the above error.
> A google search turned up a 'common errors' page on the ocaml tutorial that
> indicates I need to use type annotation. However, that example is a simple
&gt; string, and the type I have to deal with is listed as (string, (_[<
&gt; Gl.format > `rgb ], _[< Gl.kind > `ubyte ]) GlPix.t).
>
> I'm not sure where to begin to figure out how to properly annotate this.
>; Any tips or pointers to resources would be appreciated.

You are trying to store heterogeneously typed values in a language that only
supports homogeneous types. There are various ways around this. The simplest
is to support only one type and add a type annotation:

let textures : (string, ([ `rgb ], [ `ubyte ]) GlPix.t) Hashtbl.t =
Hashtbl.create 100;;

More advanced alternatives include creating a variant type that can store any
type of texture, or wrapping the texture in a class that exposes a uniform
API for all textures.

--
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
Objective CAML for Scientists
http://www.ffconsultancy.com/products/ocaml_for_scientists

__._,_.___
.

__,_._,___
"ocaml_beginners"::[] The type of this expression... contains type variables that cannot be generali
user name
2006-12-31 20:38:49


> You are trying to store heterogeneously typed values in a language that
> only supports homogeneous types. There are various ways around this.
>; The simplest is to support only one type and add a type annotation:
>
> let textures : (string, ([ `rgb ], [ `ubyte ]) GlPix.t) Hashtbl.t =
> Hashtbl.create 100;;

Thanks, that worked. But just to clarify, is it heterogeneous because the
value types normally need to match the key types? I thought it was
homogeneous because all of the keys were strings, and all of the values were
textures.

-Grant

__._,_.___
.

__,_._,___
[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )