Dear friends of Haskell,
a few days ago I asked the question:
> 2) The library proposal does not contain any advanced data structures (yet).
> How would one declare, for example, ordered sets as an instance of
> Monad[Plus]?
Alastair Reid answered as follows:
> Ordered sets are a problem because constructor classes aren't up to
> the job of describing the constraints (Eq, Ord, Ix, Hashable, etc) on
> the elements of data structures. The best you can do at the moment is
> to use the module system and qualified names to provide libraries with
> similarily interfaces. John Peterson and I wrote about this last year
> at the Haskell Workshop:
>
> ftp://haskell.cs.yale.edu/pub/haskell/yale/libs-discussion.dvi.gz
>
> ftp://haskell.cs.yale.edu/pub/haskell/yale/libs.dvi.gz
> -- draft companion paper which discusses the interface in more detail.
> -- note that libs.ps.gz is a MUCH OLDER version of this paper.
Well... The latter paper tells us (on page 2):
At the time of writing, it seems unlikely that constructor classes will be
included in Haskell 1.3.
Therefore, some proposals should perhaps be reconsidered under the new
situation. I don't see what prevents code like, for example,
instance Ord t => Monad (Set t) where ...
> (You might also want to download Hugs 1.01 from any of the usual
> ftp sites. (eg ftp.cs.nott.ac.uk) It's more or less Haskell 1.2
> but does add constructor classes - so you could play around
> with those while waiting for a full implementation of Haskell 1.3.)
HUGS does not allow the above construction. I consider this a bug. It renders
constructor classes almost useless.
By the way, I get the impression that Prelude and the libraries don't make full
use of monads yet. For example, what do you think about the following function?
lookup :: (Eq a, Monad m, MonadZero n) => a -> m (a,b) -> n b
lookup i ps = do (k,v) <- ps
if k==i then return v else zero
It surely generalises the lookup function in PreludeList (m:=[], n:=Maybe).
Best regards,
Klaus