[Haskell-cafe] The (!) operation
chrisdone at googlemail.com
Thu Mar 8 19:53:48 CET 2012
On 8 March 2012 18:32, Anthony Cowley <acowley at seas.upenn.edu> wrote:
> Perhaps Data.Key meets your needs?
Ah, perhaps indeed. Thanks!
On 8 March 2012 19:12, Francesco Mazzoli <f at mazzo.li> wrote:
> The type signature that you wrote is very generic and doesn't help in
> introducing effects while retrieving the indexed value, which I imagine is
> what you wanted to do.
Because Maybe is already a monad and it's nice to fail in the monad of
choice, e.g. if I'm in the list monad I get empty list instead, or if
I'm in the Result monad from JSON it'll fail in there. ‘Course "fail"
is suboptimal and MonadError might be better.
> I guess you could define a type family for the monad type as well, e.g.:
> type family Index f
> type family IndexMonad f :: * -> *
> class Functor f => Indexed f where
> index :: Index f -> f a -> (IndexMonad f) (Maybe a)
Right, that sounds interesting, similar to Data.Key above!
It seems like a type family is a good approach. I'll try this "keys"
Grazie mille, a dopo… ;-)
More information about the Haskell-Cafe