Basic enough questions.. 
Author Message
 Basic enough questions..

Hello folks. I'm doing a Functional module on my software
engineering course, and having recently decided to 'revise'
it, I've come across a few sticking points.

The major one at the moment which bugs me is this stillborn
attempt at an ordered binary tree data structure. It wont
load into Hugs, giving a 'Declared type too general' error
on the function type declaration, and I can't quite see why.

data Stree a = Null
             | Fork (Stree a) a (Stree a)

sInsert :: a -> (Stree a) -> (Stree a)
sInsert x Null                = Fork Null x Null
sInsert x (Fork left c right) | (c <= x) = sInsert x left
                              | (c > x)  = sInsert x right

Anyone care to point out where my misconception lies?

Thanks.

 -Graeme.



Mon, 09 Jul 2001 03:00:00 GMT  
 Basic enough questions..

Quote:

> sInsert :: a -> (Stree a) -> (Stree a)
> sInsert x Null                = Fork Null x Null
> sInsert x (Fork left c right) | (c <= x) = sInsert x left
>                               | (c > x)  = sInsert x right

Since you're comparing data items (c <= x, c > x), the type must be
an instance of the Ord class. Change the type declaration to:

  sInsert :: Ord a => a -> (Stree a) -> (Stree a)

-Levent.



Mon, 09 Jul 2001 03:00:00 GMT  
 Basic enough questions..

Quote:


> > sInsert :: a -> (Stree a) -> (Stree a)
> > sInsert x Null                = Fork Null x Null
> > sInsert x (Fork left c right) | (c <= x) = sInsert x left
> >                               | (c > x)  = sInsert x right

> Since you're comparing data items (c <= x, c > x), the type must be
> an instance of the Ord class. Change the type declaration to:

>   sInsert :: Ord a => a -> (Stree a) -> (Stree a)

Of course, if Grimace had simply deleted the type declaration from the
file, loading it andping ":type sInsert" into the interpreter would
have given that answer.

--



Mon, 09 Jul 2001 03:00:00 GMT  
 Basic enough questions..

Quote:


>>  [snip]

>Since you're comparing data items (c <= x, c > x), the type must be
>an instance of the Ord class. Change the type declaration to:

>  sInsert :: Ord a => a -> (Stree a) -> (Stree a)

Dah... So simple when you see these things, isn't it?

Thanks for your help.

 -Graeme.



Tue, 10 Jul 2001 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. mode (or why BASIC-like thinking is not enough)

2. Enough is Enough

3. Device Driver: from Apple III BASIC to IBM BASIC

4. Please help Visual Basic Programer with simple read/write text file routine---Real Basic 2.1

5. Visual basic or real basic?

6. UNIBASIC, PIC BASIC or Business Basic

7. Power Basic CC vs Power Basic for DOS

8. old BASIC to REAL BASIC ?

9. Switching to Real Basic from Visual Basic?

10. Basicly a basic BASIC

11. LabView course basic 1 and basic 2

12. Basic and Basic->C converter wanted

 

 
Powered by phpBB® Forum Software