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
> string, and the type I have to deal with is listed as (string, (_[<
> 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
.