[Haskell-beginners] Can i define a record without defining access method.
Chaddaï Fouché
chaddai.fouche at gmail.com
Sat Jul 9 18:25:13 CEST 2011
On Sat, Jul 9, 2011 at 5:59 PM, yi huang <yi.codeplayer at gmail.com> wrote:
> On Sat, Jul 9, 2011 at 6:45 PM, Tom Murphy <amindfv at gmail.com> wrote:
>>
>> On 7/9/11, yi huang <yi.codeplayer at gmail.com> wrote:
>> > I'm trying to create a haskell implementation of json rpc, I try to
>> > define
>> > protocol using record like this:
>> >
>> > data Request = Request {
>> > version :: Integer
>> > , id :: Integer
>> > , method :: String
>> > , args :: [Value]
>> > } deriving (Typeable, Data, Show)
>>
>> > so i can use json library to encode/decode it.
>> > But this code fails, because haskell will define access function
>> > automaticlly, and function names conflicts.
>> > My question is, is there a way i can define record without access
>> > function,
>> > so i can have same attribute name in multiple record.
>>
If you really want to keep those attribute names exactly, you'll have
to check where the conflict is and find a way not to import the
conflicting function name. Here I guess "id" is the big problem since
it comes with the prelude you'll have to use the NoImplicitPrelude
extension and explicitly "import Prelude hiding (id)", I suggest you
make a separate module for your type definition so you don't have to
worry about that in the rest of your code.
--
Jedaï
More information about the Beginners
mailing list