2009/7/16 Szekeres István <[email protected]>:
> class ListUpdater a where
>     updateFn :: Char -> Char
>     update :: a -> a
>
> so I can define the update function for the different types of lists:
>
> instance ListUpdater String where
>     update = map updateFn
>
> instance ListUpdater L.ByteString where
>     update = L.pack . (map updateFn) . L.unpack

So, as written, these functions both give an error, because updateFn
isn't defined.

Perhaps you want something like this:

> class CharMap a where
>     charMap :: (Char -> Char) -> (a -> a)
> instance CharMap Char where
>     charMap f = f
> instance CharMap a => CharMap [a] where
>     charMap f = map (charMap f)
> instance CharMap L.ByteString where
>     charMap f = L.pack . map f . L.unpack

Now you can write

> genericRot13, genericUL :: CharMap a => a -> a
> genericRot13 = charMap rot13
> genericUL = charMap ul

  -- ryan
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to