Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- 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 :: Nat) (o :: Nat)
- data PadTo nt (n :: Nat) 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 (t :: k) :: forall k. k -> Type = 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.
Instances
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"
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).
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)
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.
Instances
KnownSymbol a => MemRender (a :: Symbol) Source # | |
(NumberRender nt, KnownNat a, KnownNat o) => MemRender (NumberWithOffset nt a o :: Type) Source # | |
(MemRender a, MemRender b) => MemRender (a :- b :: Type) Source # | |
(MemRender a, MemRender b) => MemRender (a :| b :: Type) Source # | |
(MemRender a, Depth a <= n, NumberRender nt, KnownNat n, KnownNat (Depth a)) => MemRender (PadTo nt n a :: Type) Source # | |
type Number nt n = NumberWithOffset nt n 0 Source #
data NumberWithOffset nt (n :: Nat) (o :: Nat) Source #
Captures n
bits and convertes them to a string via the nt
("number type")
argument after adding the offset. See Dec
, Hex
.
Instances
(NumberRender nt, KnownNat a, KnownNat o) => MemRender (NumberWithOffset nt a o :: Type) Source # | |
data PadTo nt (n :: Nat) a Source #
Pad the a
argument out to length n
by taking the remaining bits
and converting them via nt
(see Dec
and Hex
). If padding is required,
it is separated by a dash.
Render numbers as decimal numbers. Does not pad.
Render numbers as hexadecimal numbers. Pads with 0s.
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 (t :: k) :: forall k. k -> Type #
Proxy
is a type that holds no data, but has a phantom parameter of
arbitrary type (or even kind). Its use is to provide type information, even
though there is no value available of that type (or it may be too costly to
create one).
Historically,
is a safer alternative to the
Proxy
:: Proxy
a'undefined :: a'
idiom.
>>>
Proxy :: Proxy (Void, Int -> Int)
Proxy
Proxy can even hold types of higher kinds,
>>>
Proxy :: Proxy Either
Proxy
>>>
Proxy :: Proxy Functor
Proxy
>>>
Proxy :: Proxy complicatedStructure
Proxy
Instances
Generic1 (Proxy :: k -> Type) | |
Monad (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
Functor (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
Applicative (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
Foldable (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
Defined in Data.Foldable fold :: Monoid m => Proxy m -> m # foldMap :: Monoid m => (a -> m) -> Proxy a -> m # foldr :: (a -> b -> b) -> b -> Proxy a -> b # foldr' :: (a -> b -> b) -> b -> Proxy a -> b # foldl :: (b -> a -> b) -> b -> Proxy a -> b # foldl' :: (b -> a -> b) -> b -> Proxy a -> b # foldr1 :: (a -> a -> a) -> Proxy a -> a # foldl1 :: (a -> a -> a) -> Proxy a -> a # elem :: Eq a => a -> Proxy a -> Bool # maximum :: Ord a => Proxy a -> a # minimum :: Ord a => Proxy a -> a # | |
Traversable (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
Alternative (Proxy :: Type -> Type) | Since: base-4.9.0.0 |
MonadPlus (Proxy :: Type -> Type) | Since: base-4.9.0.0 |
Eq1 (Proxy :: Type -> Type) | Since: base-4.9.0.0 |
Ord1 (Proxy :: Type -> Type) | Since: base-4.9.0.0 |
Defined in Data.Functor.Classes | |
Read1 (Proxy :: Type -> Type) | Since: base-4.9.0.0 |
Defined in Data.Functor.Classes | |
Show1 (Proxy :: Type -> Type) | Since: base-4.9.0.0 |
Hashable1 (Proxy :: Type -> Type) | |
Defined in Data.Hashable.Class | |
Bounded (Proxy t) | Since: base-4.7.0.0 |
Enum (Proxy s) | Since: base-4.7.0.0 |
Eq (Proxy s) | Since: base-4.7.0.0 |
Ord (Proxy s) | Since: base-4.7.0.0 |
Read (Proxy t) | Since: base-4.7.0.0 |
Show (Proxy s) | Since: base-4.7.0.0 |
Ix (Proxy s) | Since: base-4.7.0.0 |
Generic (Proxy t) | |
Semigroup (Proxy s) | Since: base-4.9.0.0 |
Monoid (Proxy s) | Since: base-4.7.0.0 |
Hashable (Proxy a) | |
Defined in Data.Hashable.Class | |
type Rep1 (Proxy :: k -> Type) | Since: base-4.6.0.0 |
type Rep (Proxy t) | Since: base-4.6.0.0 |