
On Thu, Oct 05, 2006 at 10:34:19AM +1300, tpledger@ihug.co.nz wrote:
To: haskell-cafe@haskell.org, fis@wiwi.hu-berlin.de From: tpledger@ihug.co.nz Date: Thu, 05 Oct 2006 10:34:19 +1300 Subject: [Haskell-cafe] collection monads
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'?
no, i don't need that. but aside from the fact that
data Permutation k v = Permutation [(k, v)] instance (Ix k) => Monad (Permutation k)
is redundant (i think of the permutation as a function applicable to arbitrary lists): how would that change anything? my definition of return still doesn't work. or how would you redefine 'return'? you gave me an idea, though: data Permutation a x = Permutation (Array x a -> Array x a) instance Monad (Permutation a) where return _ = Permutation id (>>=) (Permutation f) g = g f but this is dysfunctional for many reasons, too. for a start, (>>=) wouldn't really by good for anything, even if i could repair its type. composition of permutations seems to be something profoundly different from monadic binding. perhaps permutations just don't have it in them to become monads? matthias