Copyright | (c) Justin Le 2014 |
---|---|
License | MIT |
Maintainer | justin@jle.im |
Stability | stable |
Portability | portable |
Safe Haskell | None |
Language | Haskell2010 |
Internals for the library, exported in case you should need it.
Usually, the parts you would need should be re-exported in
Tagged
.
- data Tagged a
- data TagFingerprint
- tag :: Typeable a => a -> Tagged a
- getTagged :: Typeable a => Tagged a -> Maybe a
- tagMatched :: Typeable a => Tagged a -> Bool
- typeFingerprint :: Typeable a => a -> TagFingerprint
- tagFingerprint :: Tagged a -> TagFingerprint
Data types
A data type tupling together data with a TagFingerprint
,
representing data tagged with its type. You really should never have to
use this type; it's best to interface directly with data using
encodeTagged
, decodeTagged
, etc. Use tag
to tag data and
extractTagged
to extract data from valid tagged data.
data TagFingerprint Source
A data type representing a fingerprint for a Typeable
type.
Ideally, this would be Internal'
s own Fingerprint
types; however, for some reason, the fingerprints for the same data type
from the same modules differ between different GHC backends. So for
now, it is just a ByteString
representation of the name of the type.
This is literally a bad idea, and so two types with the same name but
from different modules will share a non-unique TagFingerprint
.
Hopefully in the future when I find out a way to fix this or the GHC
backend maintainers find a way to provide consistent type fingerprints,
this will be fixed.
This type is mostly used for the ability to categorized Tagged items by their type.
There is a Default
instance, because the constructor is hidden. For
now, it is just an empty ByteString
, but when fingerprinting works for
real, think of it as a way to generate a fingerprint that will most
likely not be matched by any type, in case the need ever comes up.
Tagging and extracting data
tagMatched :: Typeable a => Tagged a -> Bool Source
Check if the type inside the Tagged
matches the fingerprint.
TagFingerprint
utilities
typeFingerprint :: Typeable a => a -> TagFingerprint Source
Compute the Fingerprint
representing a type. It is non-strict on
its parameter, so passing in undefined should work if you want to just
get the Fingerprint
of a specific type without having data of that
type on hand:
typeFingerprint (undefined :: Int)
tagFingerprint :: Tagged a -> TagFingerprint Source
Extract the Fingerprint
out of a Tagged
. Mostly used so that you
can categorize and associate Tagged items; to check if a Tagged
is
of a desired typed, getTagged
and tagMatched
might be more useful.