ints are not ...

2 views
Skip to first unread message

Raoul Duke

unread,
May 18, 2022, 6:16:37 PM5/18/22
to pi...@googlegroups.com
...bitmasks, for example. 

is there a language that statically enforces such separation, not blithely allowing treating any int type as a bitmask?

David Barbour

unread,
May 19, 2022, 10:47:03 AM5/19/22
to pi...@googlegroups.com
I don't know of any language that tackles this by default. But there are languages with 'phantom types' such as units on numbers, which could be used to distinguish bitmasks from other types and also prevent bitmasks from being applied except to other bitmasks of the same type/meaning. A minimum-viable version this would be Haskell's Newtypes, which provide a type wrapper around data without changing its representation. I often use that for distinguishing different 'types' of ints that I don't want to mix by accident.

On Wed, May 18, 2022 at 5:16 PM Raoul Duke <rao...@gmail.com> wrote:
...bitmasks, for example. 

is there a language that statically enforces such separation, not blithely allowing treating any int type as a bitmask?

--
You received this message because you are subscribed to the Google Groups "PiLuD" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pilud+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pilud/CAJ7XQb4O3oAKj4qckOzuXtk_XMqkHFjWQ5_mB566pjP0j8jK_w%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages