You can avoid the underscores by defining the constants as pattern synonyms so that they are syntactically more like constructors. This also, of course, allows you to use them as patterns, which can also be nice for constants.

On Thu, Jul 6, 2017 at 9:09 AM, MarLinn <monkleyon@gmail.com> wrote:


It's got some magic values in a few places (especially that 65!)

Off topic, but sometimes when I find myself using magic values I can't/won't get rid off, I'll just apply the good old habits learned in Java times. For example you might find a section at the top of a file with things like

	_DAYS_IN_A_WEEK_ , _KNOWN_SIZE_OF_POINT_ :: INT

	-- | Seems to be a good approximation for now
	_DAYS_IN_A_WEEK_ = 7

	-- | When you ask "What's the point", this will not answer your question.
	_KNOWN_SIZE_OF_POINT_ = 65

Uppercase makes it easy to identify these as constants/magic values. The underscore in front works as an initial lowercase letter so they can be used as values despite uppercase.

The goal is not necessarily to make these values easy to change, but to add documentation to usage sites.

It's unnecessary In such a quick demonstration, but I wanted to take the opportunity to throw in my _VALUE_OF_CONTRIBUTION_IN_CENTS_ cents because I haven't seen others do something like this.


Cheers,
MarLinn


PS: The underscore does introduce its own error message though.

    • Found hole: _VALUE_OF_CONTRIBUTION_IN_CENTS_ :: Double
      Or perhaps ‘_VALUE_OF_CONTRIBUTION_IN_CENTS_’ is mis-spelled, or not in scope



_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.