Abstract Data Type problem 
Author Message
 Abstract Data Type problem

Here's my code:

module Stack (Stack, makeStack)  where

data Stack t       = StackC [t]  deriving (Read, Show, Eq)

makeStack :: Stack t
makeStack = StackC []

this module loads but I get a "can't find show funciton when I run
makeStack.

to get around this I had to hard code the type as StackC [Int]:

data Stack t    = StackC [Int] deriving .....

and then it worked.  My question is how can I make this Stack t polymorphic,
able to work with other than type Ints?  TIA   email:



Thu, 02 Aug 2001 03:00:00 GMT  
 Abstract Data Type problem

Quote:
>Here's my code:

>module Stack (Stack, makeStack)  where

>data Stack t       = StackC [t]  deriving (Read, Show, Eq)

>makeStack :: Stack t
>makeStack = StackC []

>this module loads but I get a "can't find show funciton when I run
>makeStack.

Try using an explicit type qualifier when you run it, e.g.
typing `makeStack :: Stack [Int]' at the Hugs prompt.

Quote:
>to get around this I had to hard code the type as StackC [Int]:

>data Stack t    = StackC [Int] deriving .....

>and then it worked.  My question is how can I make this Stack t polymorphic,
>able to work with other than type Ints?

Your original definition is polymorphic, and works fine.
The problem is just that the interpreter won't print out a polymorphic value
without you telling the interpreter what type it should use (since, in some
cases, the output can depend on the type).

--

WWW: <http://www.cs.mu.oz.au/~fjh>  |   but source code lives forever"



Fri, 03 Aug 2001 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Deriving abstract types from abstract types

2. Abstract Data Types book

3. abstract data type

4. Abstract data types in Haskell

5. Abstract Data Type in FP

6. Abstract Data Types book

7. Abstract data types and uniform treatment of opertors

8. abstract data type linked list

9. abstract data types and structures

10. Abstract data types and structures

11. Abstract data types: FP and OOP?

12. Abstract DAta Types

 

 
Powered by phpBB® Forum Software