[Haskell-cafe] Magic values, WAS: Encrypting streamed data
jake.mcarthur at gmail.com
Sat Jul 8 15:07:07 UTC 2017
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
On Thu, Jul 6, 2017 at 9:09 AM, MarLinn <monkleyon at 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.
> 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:
> Only members subscribed via the mailman list are allowed to post.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe