Safe Haskell | None |
---|---|
Language | Haskell2010 |
- renderMemorable :: (MemRender p, Depth p ~ MemLen a, Memorable a) => Proxy p -> a -> String
- parseMemorable :: (Memorable a, MemRender p, MemLen a ~ Depth p) => Proxy p -> String -> Maybe a
- rerender :: (MemRender a, MemRender b, Depth a ~ Depth b) => Proxy a -> Proxy b -> String -> Maybe String
- class Memorable a where
- (.-) :: Proxy a -> Proxy b -> Proxy (a :- b)
- (.|) :: Depth a ~ Depth b => Proxy a -> Proxy b -> Proxy (a :| b)
- two :: Proxy a -> Proxy (a :- a)
- three :: Proxy a -> Proxy ((a :- a) :- a)
- four :: Proxy a -> Proxy (((a :- a) :- a) :- a)
- five :: Proxy a -> Proxy ((((a :- a) :- a) :- a) :- a)
- padHex :: forall n a. Proxy a -> Proxy (PadTo Hex n a)
- padDec :: forall n a. Proxy a -> Proxy (PadTo Dec n a)
- hex :: Proxy (Number Hex n)
- hex4 :: Proxy (Number Hex 4)
- hex8 :: Proxy (Number Hex 8)
- hex16 :: Proxy (Number Hex 16)
- hex32 :: Proxy (Number Hex 32)
- dec :: Proxy (Number Dec n)
- dec4 :: Proxy (Number Dec 4)
- dec8 :: Proxy (Number Dec 8)
- dec16 :: Proxy (Number Dec 16)
- dec32 :: Proxy (Number Dec 32)
- type family ToTree (a :: [k]) :: * where ...
- leftSide :: Proxy (a :| b) -> Proxy a
- rightSide :: Proxy (a :| b) -> Proxy b
- data a :- b
- class MemRender a
- type Number nt n = NumberWithOffset nt n 0
- data NumberWithOffset nt n o
- data PadTo nt n a
- data Dec
- data Hex
- type family Depth (a :: k) :: Nat where ...
- getDepth :: forall a. KnownNat (Depth a) => Proxy a -> Integer
- type family LeftSide (a :: *) :: * where ...
- type family RightSide (a :: *) :: * where ...
- data Proxy k t :: forall k. k -> * = Proxy
Documentation
renderMemorable :: (MemRender p, Depth p ~ MemLen a, Memorable a) => Proxy p -> a -> String Source #
This is the function to use when you want to turn your values into a memorable strings.
>>>
import Data.Word
>>>
import Data.Memorable.Theme.Words
>>>
let myPattern = words8 .- words8
>>>
renderMemorable myPattern (0x0123 :: Word16)
"cats-bulk"
parseMemorable :: (Memorable a, MemRender p, MemLen a ~ Depth p) => Proxy p -> String -> Maybe a Source #
Turn a memorable string back into a Memorable
value.
rerender :: (MemRender a, MemRender b, Depth a ~ Depth b) => Proxy a -> Proxy b -> String -> Maybe String Source #
Convert a memorable string into a different memorable string.
Useful for things like taking an existing md5, and converting it into a memorable one.
>>>
:set -XTypeApplications -XDataKinds
>>>
import Data.Memorable.Theme.Words
>>>
rerender hex (padHex @128 $ four words10) "2d4fbe4d5db8748c931b85c551d03360"
Just "lurk-lash-atop-hole-b8748c931b85c551d03360"
class Memorable a where Source #
Class for all things that can be converted to memorable strings.
See renderMemorable
for how to use.
Pattern Building
(.-) :: Proxy a -> Proxy b -> Proxy (a :- b) Source #
Proxy version of :-
.
The new pattern depth is the sum of the two parts.
>>> import Data.Word
>>> import Data.Memorable.Theme.Words
>>> let myPattern = words8 .- words8
>>> renderMemorable myPattern (0xabcd :: Word16)
"ages-old"
(.|) :: Depth a ~ Depth b => Proxy a -> Proxy b -> Proxy (a :| b) Source #
Proxy version of :|
. It also constraints the two subpatterns to
being the same depth. Use this to add an extra bit to the pattern depth,
where the bit chooses to proceed down either the left or right side.
>>>
:set -XTypeApplications
>>>
:set -XDataKinds
>>>
import Data.Word
>>>
let myPattern = padHex (Proxy @"foo" .| Proxy @"bar")
>>>
renderMemorable myPattern (0x00 :: Word8)
"bar-00">>>
renderMemorable myPattern (0xff :: Word8)
"foo-7f"
See also ToTree
WARNING: Each side of the split must be unique. See the warning about :|
.
five :: Proxy a -> Proxy ((((a :- a) :- a) :- a) :- a) Source #
Put five things next to each other.
Same as using .-
repeatedly
padHex :: forall n a. Proxy a -> Proxy (PadTo Hex n a) Source #
Pad this pattern out with hex digits. Useful when you want some human
readability, but also want full coverage of the data. See Hex
for details.
>>>
import Data.Word
>>>
import Data.Memorable.Theme.Fantasy
>>>
renderMemorable (padHex rpgWeapons) (0xdeadbeef01020304 :: Word64)
"sacred-club-of-ghoul-charming-eef01020304"
The depth to pad to is the first type-level argument. If you have
TypeApplications
set, you can use it like `padHex @256` to be
explicit.
hex :: Proxy (Number Hex n) Source #
A single hex number consuming n
bits, which it will try and figure
out from context (with leading 0's). Using TypeApplications
allows you
to specify the size directly, `hex @32 == hex32`.
dec :: Proxy (Number Dec n) Source #
A single decimal number consuming n
bits, which it will try and figure
out from context (no leading 0's). Using TypeApplications
allows you
to specify the size directly, `dec @32 == hex32`.
type family ToTree (a :: [k]) :: * where ... Source #
Convert a '[Symbol]
to a balanced tree of :|
. Each result has equal
probability of occurring. Length of the list must be a power of two. This
is very useful for converting long lists of words into a usable pattern.
>>>
:kind! ToTree '["a", "b", "c", "d"]
ToTree '["a", "b", "c", "d"] :: * = ("a" :| "b") :| ("c" :| "d")
leftSide :: Proxy (a :| b) -> Proxy a Source #
Shrink a branching pattern by discarding the right hand side.
rightSide :: Proxy (a :| b) -> Proxy b Source #
Shrink a branching pattern by discarding the left hand side.
Pattern Types
Append two patterns together by doing the first, then the second. See
also .-
The class that implements the main rendering function.
KnownSymbol a => MemRender Symbol a Source # | |
(NumberRender k nt, KnownNat a, KnownNat o) => MemRender * (NumberWithOffset k nt a o) Source # | |
(MemRender k1 a, MemRender k b) => MemRender * ((:-) k k1 a b) Source # | |
(MemRender k1 a, MemRender k b) => MemRender * ((:|) k k1 a b) Source # | |
(MemRender k1 a, (<=) (Depth k1 a) n, NumberRender k nt, KnownNat n, KnownNat (Depth k1 a)) => MemRender * (PadTo k1 k nt n a) Source # | |
type Number nt n = NumberWithOffset nt n 0 Source #
data NumberWithOffset nt n o Source #
Captures n
bits and convertes them to a string via the nt
("number type")
argument after adding the offset. See Dec
, Hex
.
(NumberRender k nt, KnownNat a, KnownNat o) => MemRender * (NumberWithOffset k nt a o) Source # | |
type family Depth (a :: k) :: Nat where ... Source #
Determines the number of bits that a pattern will consume.
getDepth :: forall a. KnownNat (Depth a) => Proxy a -> Integer Source #
Get the depth of a pattern as a value-level Integer
.
>>> :set -XTypeApplications -XDataKinds
>>> getDepth (Proxy "foo" .| Proxy
"bar")
1
type family LeftSide (a :: *) :: * where ... Source #
Useful to prevent haddock from expanding the type.
type family RightSide (a :: *) :: * where ... Source #
Useful to prevent haddock from expanding the type.
Re-export
data Proxy k t :: forall k. k -> * #
A concrete, poly-kinded proxy type
Monad (Proxy *) | |
Functor (Proxy *) | |
Applicative (Proxy *) | |
Foldable (Proxy *) | |
Generic1 (Proxy *) | |
Alternative (Proxy *) | |
MonadPlus (Proxy *) | |
Eq1 (Proxy *) | Since: 4.9.0.0 |
Ord1 (Proxy *) | Since: 4.9.0.0 |
Read1 (Proxy *) | Since: 4.9.0.0 |
Show1 (Proxy *) | Since: 4.9.0.0 |
Hashable1 (Proxy *) | |
Bounded (Proxy k s) | |
Enum (Proxy k s) | |
Eq (Proxy k s) | |
Ord (Proxy k s) | |
Read (Proxy k s) | |
Show (Proxy k s) | |
Ix (Proxy k s) | |
Generic (Proxy k t) | |
Semigroup (Proxy k s) | |
Monoid (Proxy k s) | |
Hashable (Proxy * a) | |
type Rep1 (Proxy *) | |
type Rep (Proxy k t) | |