use of undefined type
Wolfgang Jeltsch
wolfgang@jeltsch.net
Thu, 28 Feb 2002 17:42:46 +0100
On Wednesday, February 2, 2002, 22:32 CET Andre W B Furtado wrote:
> I'm developing a tool that will help game programmers to develop games in
> Haskell. To create a game object, the programmer must call the function
> *object* as follows:
>
> object name_of_object position_of_object speed_of_object
>
> I would like also to add another param to this function, which type would be
> anyone defined by the programmer. Unfortunately, as Haskell does not allow
> things like:
>
> type Game = (Name,Position,Speed,t)
>
> where t is an undefined type, I'm forced to add "t" to the left side of the
> type synonym (type Game t = ...). But this is realling doing a mess in my
> code, since I have to pass this "t" all around. That's why I ask if anyone
> knows another idea to solve this problem...
Hello,
I think, if your code doesn't has to be Haskell 98 compliant, you could use a
universally quantified type like this:
data Object = forall t. Object String (Double,Double) Double t
But in this example, you won't be able to do anything useful with the
encapsulated value of type t. How Object would have to be defined to do
useful things with the encapsulated value, would depend on what you want to
do with it.
> Thanks a lot,
> -- Andre W
Your welcome,
Wolfgang