Data type design in Haskell -


Learning Haskell, I write the formator for C ++ header files. First of all, I parse members of all classes in a-collection-of-class-members , which then goes to the formatting routine. To show members of the class I have

  data classmember = CMTPF typefif. CMI method | CMOperloadOverload operator overload | CMV Variable Variable | CMFRandCell Friendclose | CMDSTstructor Destructor  

(Due to some specifications of the formatting style, I need to classify class members like this.)

The problem is that I get the "drag" class For example, type a function defined for member code classmember , I have to write a lot of unnecessary code, for example

  Example formatted class members where format (CMTEPEF TD) = Format Tide Format (CMMIDM) = Format M Format (CMOperator Overload OO) = Format OO Format (CMVaraable V) = Format V Format (CMFAR and Class FC) = Format FC Format (CMDSTstructor D) = Format D Example Confusing Classmember Where - The same story here < / Code> 

On the other hand, I definitely have objects (at least, I think so), so it's

  Data classmember = Do Clasmember defined as an example. Formatting Classmember One Format (Classmember A) = One Format  

does not seem to be an option.

The options I am considering:

  1. classmember not the object inserts itself, but the fax is defined on the same type Which are required by the formatting routine. The parsing result provided by [classmember] should be aware of all its uses.

  2. Define this approach breaks the modularity, the IMO, classmember as an existential type, therefore [classmember] There is no problem now. I doubt whether this design is very strict and then, I need to specify all the constraints in definition, such as Data ClassMember = forall a formatting one => Classmember A . In addition, I prefer a solution without using extensions.

Am I doing a proper way of doing it in Haskell or is there a better way?

First, trim the ATT a little bit below. Operator overloads and destructors are special type of methods, so it can understand more to treat CmMethod in all three; After that, there will be special ways to isolate them. Alternatively, keep all three of CmMethod , CmOperatorOverload , and CMDststructor , but all of them have the same Method Type.

But obviously, you can only reduce the complexity.

For a specific example of a show example: You do not really want to leave yourself except some special cases for your case, to get it automatically Example is more appropriate:

  Data ClassMember = CmTypedef Typedef | CMI method | ... | CMD Structure Distribute Derivating (Show)  

This will give you different results from your custom instances & ndash; Because you are wrong: showing the implied results should also be given information about the constructor.

If you do not really want to show in but another class C which ClassMember s & ndash; Makes more specific for; OK, you probably should not have defined the first <<> code ! The purpose of type classes is to express mathematical concepts which are for many types of type.


Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -