[Haskell-cafe] Magic values
MarLinn
monkleyon at gmail.com
Sat Jul 8 17:40:05 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 constants.
>
> 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
>
Nice! This seems a bit evil, and not a full substitute. But it also
helps hijack syntax highlighting, and it forces users to use a
recent-ish version of GHC. I consider that A Good Thing™.
Now… as everything is “constant” in Haskell, on to define everything in
capital letter patterns and return to good old COBOL times!
🍺 Wohoo!
Cheers,
MarLinn
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20170708/e2934384/attachment.html>
More information about the Haskell-Cafe
mailing list