[Haskell-cafe] Restricted type classes
C. McCann
cam at uptoisomorphism.net
Fri Sep 3 13:01:58 EDT 2010
On Fri, Sep 3, 2010 at 11:47 AM, John Lato <jwlato at gmail.com> wrote:
> On Fri, Sep 3, 2010 at 1:29 PM, Ivan Lazar Miljenovic <ivan.miljenovic at gmail.com> wrote:
>> On 3 September 2010 22:23, John Lato <jwlato at gmail.com> wrote:
>> > Do you have a kind * implementation of Foldable? I'd be interested in
>> > seeing it, because I was unable to create a usable implementation (based
>> > upon the RMonad scheme) on my last attempt.
>>
>> I was going to make it a subset of Foldable: fold, foldr, foldl, etc.
>
> So you don't have a working implementation yet? I ended up thinking this is
> impossible, although I don't remember the reasoning that led me to that
> conclusion (and I could very well be wrong).
> I would suggest that you check this before going too far along the
> restricted-monad path.
This sounds odd to me. An RMonad-style version of Foldable is straightforward:
class RFoldable t where
rfold :: Control.RMonad.Suitable t a => (a -> b -> b) -> b -> t a -> b
instance RFoldable Data.Set.Set where
rfold = Data.Set.fold
A similar class for types of kind * is also straightforward:
class Reduce t where
type Elem t
reduce :: (Elem t -> r -> r) -> r -> t -> r
instance Reduce Data.ByteString.ByteString where
type Elem Data.ByteString.ByteString = Word8
reduce = Data.ByteString.foldr
Both seem to work as I'd expect. Am I missing something? Foldable is
pretty trivial--perhaps it was Traversable that you found problematic?
- C.
More information about the Haskell-Cafe
mailing list