Re: [Haskell-cafe] Re: Data.Binary Endianness
* apfelmus wrote: > It's not that related, but I just got struck by an obvious idea, namely > to put the endianness in an extra parameter > >data Endianness = Little | Big | Host >putInt32 :: Endianness -> Int -> Put Please add the endianess to the state of the monad "Put". setendianess :: Endianness -> Put And for convinience please add the "Network" constructor to the type "Endianness". ,-) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Data.Binary Endianness
On Monday 10 September 2007 21:02, apfelmus wrote: > [...] >class Put a endian where > put :: endian -> a -> Put > [...] > Oh, and the 8,16,32 and 64 are good candidates for phantom > type/associated data types, too. I think that using any non-H98 feature like MPTC or associated data types for such a generally useful and basic package would be a *big* mistake. Let's follow the "KISS" principle here. Everybody is free to make a nicer, but non-portable wrapper... Cheers, S. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Data.Binary Endianness
Sven Panne wrote: > So what I was asking for is: getInt32be, putIEEEFloatLe, getIEEEDoubleHost, ... Type classes might be used to get a slightly smaller API, but I am unsure about the performance impact and how much this would really buy us in terms of the ease of use of the API. It's not that related, but I just got struck by an obvious idea, namely to put the endianness in an extra parameter data Endianness = Little | Big | Host putInt32 :: Endianness -> Int -> Put in order to avoid three functions for every data type. I don't know whether this makes performance a bit worse, but if it does, phantom types or similar are an option to encode endianness, too. data LE = LE data BE = BE data Host = Host class Put a endian where put :: endian -> a -> Put instance Put Int32 LE where ... instance Put Int32 BE where ... instance Put Int32 Host where ... Oh, and the 8,16,32 and 64 are good candidates for phantom type/associated data types, too. Regards, apfelmus ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe