On Wed, Apr 27, 2011 at 09:46:08PM +0200, Maciej Marcin Piechotka wrote: > > I believe following should work > > class Serializer ObjectA where > get = check =<< (ObjectA <$> get <*> get <*> get) > where check obj@(ObjectA len id attr) > | len < 10 && id == 0 = return obj > | otherwise = empty > > class Serializer ObjectB where > get = check =<< (ObjectB <$> get <*> get <*> get) > where check obj@(ObjectB len id attr) > | len > 10 && id == 1 = return obj > | otherwise = empty > > parseEitherAB :: Get (Either ObjectA ObjectB) > parseEitherAB = (Left <$> get) <|> (Right <$> get)
Hum, that's still not automatic but using Control.Applictive to write one-liners seems a good-enough solution. I will try it. thanks ,) /john _______________________________________________ Haskell-Cafe mailing list [email protected] http://www.haskell.org/mailman/listinfo/haskell-cafe
