[Haskell-cafe] The difficulty of designing a sequence class

Einar Karttunen ekarttun at cs.helsinki.fi
Tue Aug 1 05:58:30 EDT 2006


On 31.07 16:27, Brian Hulley wrote:
> None of the above type classes would be compatible with Data.ByteString! 
> (You mentioned this issue before wrt Data.Edison.Seq but it just clicked 
> with me now for the above refactoring.) For compatibility, the element type 
> would need to appear also thus:
> 
>   class Foldable f_a a | f_a -> a where
>        fold :: (a -> b -> b) -> b -> f_a -> b
> 

With the new System FC (when it is merged) we could make these classes
nicer.

class ElementType c a | c -> a

instance ElementType [a] a
instance ElementType ByteString Char
instance IArray a e => ElementType (a i e) e

class Foldable c where
  fold :: ElementType c a => (a -> b -> b) -> b -> c -> b

This won't work at the moment due to limitations in GHC, but seems
like a cleaner solution.

- Einar Karttunen


More information about the Haskell-Cafe mailing list