[Haskell-cafe] Review request for my encoding function

C K Kashyap ckkashyap at gmail.com
Sat Jan 8 10:58:33 CET 2011


Thanks Ivan,

> The more "Haskellian" approach would be to use a dedicated datatype to
> specify the number of bits, not to have a partial function on Int.
> Possibly even encode the RGB triple such that it specifies the number
> of bits rather than separating each value.

Did you mean something like this?

data BitsPerPixel = Bpp8 | Bpp16 | Bpp32

encode :: Color -> BitsPerPixel -> Int-> Int-> Int-> Int-> Int-> Int
-> ByteString
encode (r,g,b) bitsPerPixel redMax greenMax blueMax redShift
greenShift blueShift = runPut $ do
	case bitsPerPixel of
		Bpp8	-> putWord8 z8
		Bpp16	-> putWord16be z16
		Bpp32	-> putWord32be z32

Regards,
Kashyap



More information about the Haskell-Cafe mailing list