I'm having trouble revamping the design of some things I would
naturally do a particular way with instances, but that can't
at the moment be done because of certain constraints on the
type parameters in instances on kinds (*->*). More specifically,
I'm thinking I want to do something like

\begin{impossible-code}
instance Monad Set where
    (Set xs) >>= f = foldr (\/) empty (f `fmap` xs)
    return x = Set [x]
\end{impossible-code}

(where (\/) is a Lattice operator that on sets takes unions)
The type constructor Set (of kind *->*) requires Eq a of its argument.
This yields the error
ERROR "Set.lhs" (line 51): Cannot justify constraints in instance member binding
*** Expression    : (>>=)
*** Type          : Monad Set => Set a -> (a -> Set b) -> Set b
*** Given context : Monad Set
*** Constraints   : Eq b

My question in this case is what sorts of general techniques might
be recommended to naturally avoid this particular sort of error.
That is, if I'm thinking of trying to do something like this, how
should I be doing things instead in general?

Back to specifics, the sort of thing I'm thinking of trying to do
here is I'll have an algorithm which tries to compute some set
by some fixed point-like computation, where the iteration step is
some function that examines every element of the set, computes
another set from each element, and then the next element of the
sequence is the union of all those given things (just like the set
Monad talks about as the result of (>>=) in this and ListMonad).  So
the idea is to express this whole computation as
\begin{idealized-code}
        fixM (>>= f) smallStartingSet where ...
\end{idealized-code}
for the appropriate function f.

I hope this is enough background information for someone to perhaps
give a small bit of methodological advice.

Thanks,
Bill
-- 
"Doubtless every reader has heard something of the ingenious
theory of monads --- miniature replicas of the universe out of
which everything in the universe is composed, as a sort of one in
all, all in one --- by which Leibniz explained everything (except
the monads) in this world and the next."
-- E.T.Bell in "Men of Mathematics", pg. 128.

Reply via email to