Re: How to make Data.Set.Set a Functor

2005-10-12 Thread Ketil Malde
Lajos Nagy [EMAIL PROTECTED] writes:

 On the other hand, it seems intuitively natural to make Set an
 instance of fmap. 

Indeed.  While I generally like the overloaded, qualified names, I
find it annoying when, like 'map', they clash with Prelude imports.
Which means that, in a module using Data.Set, I must either use it all
qualified, or import it twice (qualified and hiding map), or
explicitly import Prelude hiding map.  (Better solutions wanted!)

-k
-- 
If I haven't seen further, it is by standing in the footprints of giants

___
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


RE: How to make Data.Set.Set a Functor

2005-10-12 Thread Simon Marlow
On 11 October 2005 17:16, Lajos Nagy wrote:

 While working on a toy compiler I realized that Data.Set.Set (Set) is
 not an instance of the Functor class.  In other words: 'fmap' is not
 defined on it.  I tried various ways of defining an instance but I
 failed.  The reason is quite interesting: Set is a type constructor
 (* - *) so it should qualify it for being a Functor.  (In a sense it
 is very similar to a Map or a list.)  However, most Set functions
 require the elements of the Set to be an instance of Ord.  The
 problem is that this constraint cannot be deduced from the instance
 declaration for Functor: 
 
 instance Functor Data.Set.Set where
 fmap f s = Data.Set.map f s

A nice way to do this would be:

  data FSet a where
 FSet :: Ord a = Set a - FSet a

  instance Functor FSet where 
 ...

if only GADTs worked with type classes :-)

Cheers,
Simon
___
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


Re: How to make Data.Set.Set a Functor

2005-10-11 Thread Benjamin Franksen
On Tuesday 11 October 2005 18:16, Lajos Nagy wrote:
 While working on a toy compiler I realized that Data.Set.Set (Set) is
 not an instance of the Functor class.  In other words: 'fmap' is not
 defined on it.  I tried various ways of defining an instance but I
 failed.  The reason is quite interesting: Set is a type constructor
 (* - *) so it should qualify it for being a Functor.  (In a sense it
 is very similar to a Map or a list.)  However, most Set functions
 require the elements of the Set to be an instance of Ord.  The
 problem is that this constraint cannot be deduced from the instance
 declaration for Functor:

 [...]

 On the other hand, it seems intuitively natural to make Set an
 instance of fmap.  Any ideas on how to do it?

Hi,

you are not the first one to observe this. AFAIK, there is no really 
satisfactory solution available. The general problem is discussed and a 
solution (a language extension) proposed in 
(http://www.cs.chalmers.se/~rjmh/Papers/restricted-datatypes.ps).

Cheers,
Ben
___
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users