
Matthias Fischmann wrote:
another beginners question about monads: given the type
| data (Ix x) => Permutation x = Permutation [x]
i wanted to define
| instance Monad Permutation where | return xs = Permutation xs
but of course nothing about the monad class guarantees xs to be of type list. the monad class seems unsuitable for holding
collections, > and i am inclined to not instantiate permutations. > > just to be sure: is there any easy way to do it that i missed?
Do you expect the contained type x to change during a sequence of monadic actions? e.g. would you ever use (>>=) at the type 'Permutation Int -> (Int -> Permutation Bool) -> Permutation Bool'? If not, you could separate each permutation into keys and values: data Permutation k v = Permutation [(k, v)] instance (Ix k) => Monad (Permutation k) Regards, Tom