Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

f# class constructor formatting

I am creating a program that takes an email and converts it into json. In the interest of learning functional languages I thought it would be a good opportunity to learn F#. So first off I want a message class that can then easily be serialized into json. This class will have some members that can be null. Because of these optional parameters I am using the following format

type Email(from:string, recipient:string, ?cc:string .........) =
    member x.From = from
    member x.Recipient = recipient.....

This class actually has a lot of members as I want to store every piece of information that an email could have. What happens is if I try to format the constructor myself by splitting it onto multiple lines I get warnings. How do people make such a gigantic constructor look good in f#? Is there a better way to do this?

On a similar note, I'm not finding visual studio very helpful for f#, what are other people using to code? I think there is a mode for emacs for example...

like image 560
shmish111 Avatar asked Mar 02 '26 17:03

shmish111


1 Answers

There should not be any warnings if all "newlined" parameters start at the same column. For example:

type Email(from:string, recipient:string,
           ?cc:string) =
    member x.From = from
    member x.Recipient = recipient

(I personally enjoy using Visual Studio for F#. I doubt there is an IDE with more complete support.)

like image 111
wmeyer Avatar answered Mar 05 '26 18:03

wmeyer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!