haskell - Sum Type Vs Record of Maybes -


While designing the data type in Haskell, I am facing a problem often, or it may be that the type or records used by the intritor may be used.

Fx will be a simple example for operation, spot or forwarding, where the only difference is the presence of "maturation" or not (on one side there must be a certain type of use which is clearly specified. Is a place or forward.

  data amount = amount {amount :: double, currency :: string} data Fx = Spot {tranDate :: day, quantity sold: amount, purchased money :: Zodiac} | Next {Trandet :: Days, Amount Paid: Zodiac, Purchase Hammount :: Zodiac, Maturity :: Day}  

Another method is that only maturity can be as a 'may'

< Pre> data Fx = Fx {tranDate :: day, sold quantity :: amount, purchased atmount :: amount, maturity (probably day)}

or anything

S = "post-text" itemprop = "text">

I do not recommend working with types of types that are named field that are unsafe for the accessers Are on any one of the branches If they are replicated in the area, they are not very dry.

But instead of putting maybe inside a record, I define the wrapping record, such as:

  data spot = spot {tranDate :: day, soldAmount :: amount, purchased money: amount} data forward = next {spot :: spot, maturity :: day}  

and even even HasSpot type classes will also implement both space and forward .

But now it is difficult to put spots and forward values ​​in the same collection. Perhaps someone could use a type like (maybe day, spot) in that way.

The "Wrap it" approach of this answer is not very well suited for more than one optional field, though.


Comments

Popular posts from this blog

winforms - C# Form - Property Change -

javascript - amcharts makechart not working -

java - Algorithm negotiation fail SSH in Jenkins -