[Haskell-cafe] Restricted type classes
John Lato
jwlato at gmail.com
Sun Sep 5 08:31:14 EDT 2010
On Fri, Sep 3, 2010 at 12:01 PM, C. McCann <cam at uptoisomorphism.net> wrote:
> 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?
>
This certainly does seem to work just fine in ghc-6.12, but not 6.10.4. I
wonder if that was the source of my problems last time.
John
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20100905/454217e7/attachment.html
More information about the Haskell-Cafe
mailing list