| Copyright | (c) 2025 Jared Tobin |
|---|---|
| License | MIT |
| Maintainer | Jared Tobin <jared@ppad.tech> |
| Safe Haskell | None |
| Language | Haskell2010 |
Data.Choice
Description
Constant-time choice.
Synopsis
- data Choice :: TYPE 'WordRep
- true# :: () -> Choice
- false# :: () -> Choice
- decide :: Choice -> Bool
- to_word# :: Choice -> Word#
- newtype MaybeWord# :: TYPE ('TupleRep '['WordRep, 'WordRep]) = MaybeWord# (# Word#, Choice #)
- some_word# :: Word# -> MaybeWord#
- none_word# :: Word# -> MaybeWord#
- newtype MaybeWide# :: TYPE ('TupleRep '['TupleRep '['WordRep, 'WordRep], 'WordRep]) = MaybeWide# (# (# Word#, Word# #), Choice #)
- some_wide# :: (# Word#, Word# #) -> MaybeWide#
- just_wide# :: (# Word#, Word# #) -> Choice -> MaybeWide#
- none_wide# :: (# Word#, Word# #) -> MaybeWide#
- expect_wide# :: MaybeWide# -> String -> (# Word#, Word# #)
- expect_wide_or# :: MaybeWide# -> (# Word#, Word# #) -> (# Word#, Word# #)
- from_word_mask# :: Word# -> Choice
- from_word# :: Word# -> Choice
- from_word_nonzero# :: Word# -> Choice
- from_word_eq# :: Word# -> Word# -> Choice
- from_word_le# :: Word# -> Word# -> Choice
- from_word_lt# :: Word# -> Word# -> Choice
- from_word_gt# :: Word# -> Word# -> Choice
- from_wide# :: (# Word#, Word# #) -> Choice
- from_wide_le# :: (# Word#, Word# #) -> (# Word#, Word# #) -> Choice
- or# :: Choice -> Choice -> Choice
- and# :: Choice -> Choice -> Choice
- xor# :: Choice -> Choice -> Choice
- not# :: Choice -> Choice
- ne# :: Choice -> Choice -> Choice
- eq# :: Choice -> Choice -> Choice
- select_word# :: Word# -> Word# -> Choice -> Word#
- select_wide# :: (# Word#, Word# #) -> (# Word#, Word# #) -> Choice -> (# Word#, Word# #)
- select_wider# :: (# Word#, Word#, Word#, Word# #) -> (# Word#, Word#, Word#, Word# #) -> Choice -> (# Word#, Word#, Word#, Word# #)
- eq_word# :: Word# -> Word# -> Choice
- eq_wide# :: (# Word#, Word# #) -> (# Word#, Word# #) -> Choice
- eq_wider# :: (# Word#, Word#, Word#, Word# #) -> (# Word#, Word#, Word#, Word# #) -> Choice
Choice
data Choice :: TYPE 'WordRep Source #
Constant-time choice, encoded as a mask.
Note that Choice is defined as an unboxed newtype, and so a
Choice value cannot be bound at the top level. You should work
with it locally in the context of a computation.
It's safe to decide a choice, reducing it to a Bool, at any
time, but the general encouraged pattern is to do that only at the
end of a computation.
>>>decide (or# (false# ()) (true# ()))True
MaybeWord#
newtype MaybeWord# :: TYPE ('TupleRep '['WordRep, 'WordRep]) Source #
Constructors
| MaybeWord# (# Word#, Choice #) |
some_word# :: Word# -> MaybeWord# Source #
none_word# :: Word# -> MaybeWord# Source #
MaybeWide#
newtype MaybeWide# :: TYPE ('TupleRep '['TupleRep '['WordRep, 'WordRep], 'WordRep]) Source #
Constructors
| MaybeWide# (# (# Word#, Word# #), Choice #) |
some_wide# :: (# Word#, Word# #) -> MaybeWide# Source #
just_wide# :: (# Word#, Word# #) -> Choice -> MaybeWide# Source #
none_wide# :: (# Word#, Word# #) -> MaybeWide# Source #
expect_wide# :: MaybeWide# -> String -> (# Word#, Word# #) Source #
expect_wide_or# :: MaybeWide# -> (# Word#, Word# #) -> (# Word#, Word# #) Source #
Construction
from_word_mask# :: Word# -> Choice Source #
Construct a Choice from an unboxed mask.
The input is not checked.
>>>decide (from_word_mask# 0##)False>>>decide (from_word_mask# 0xFFFFFFFFF_FFFFFFFF##)True
from_word# :: Word# -> Choice Source #
Construct a Choice from an unboxed word, which should be either
0## or 1##.
The input is not checked.
>>>decide (from_word# 1##)True
from_word_nonzero# :: Word# -> Choice Source #
Construct a Choice from a nonzero unboxed word.
The input is not checked.
>>>decide (from_word_nonzero# 2##)True
from_word_eq# :: Word# -> Word# -> Choice Source #
Construct a Choice from an equality comparison.
>>>decide (from_word_eq# 0## 1##)False decide (from_word_eq# 1## 1##) True
from_word_le# :: Word# -> Word# -> Choice Source #
Construct a 'Choice from an at most comparison.
>>>decide (from_word_le# 0## 1##)True>>>decide (from_word_le# 1## 1##)True
from_word_lt# :: Word# -> Word# -> Choice Source #
Construct a Choice from a less-than comparison.
>>>decide (from_word_lt# 0## 1##)True>>>decide (from_word_lt# 1## 1##)False
from_word_gt# :: Word# -> Word# -> Choice Source #
Construct a Choice from a greater-than comparison.
>>>decide (from_word_gt# 0## 1##)False>>>decide (from_word_gt# 1## 1##)False
from_wide# :: (# Word#, Word# #) -> Choice Source #
Construct a Choice from a two-limb word, constructing a mask from
the lower limb, which should be 0## or 1##.
The input is not checked.
>>>decide (from_wide# (# 0##, 1## #))False
from_wide_le# :: (# Word#, Word# #) -> (# Word#, Word# #) -> Choice Source #
Construct a Choice from an at most comparison on a two-limb
unboxed word.
>>>decide (from_wide_le# (# 0##, 0## #) (# 1##, 0## #))True>>>decide (from_wide_le# (# 1##, 0## #) (# 1##, 0## #))True
Manipulation
Constant-time Selection
select_wide# :: (# Word#, Word# #) -> (# Word#, Word# #) -> Choice -> (# Word#, Word# #) Source #
Select an unboxed two-limb word, given a Choice.
select_wider# :: (# Word#, Word#, Word#, Word# #) -> (# Word#, Word#, Word#, Word# #) -> Choice -> (# Word#, Word#, Word#, Word# #) Source #
Select an unboxed four-limb word, given a Choice.
Constant-time Equality
eq_word# :: Word# -> Word# -> Choice Source #
Compare unboxed words for equality in constant time.
>>>decide (eq_word# 0## 1##)False