Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
This module exports:
- Data types with
ContentAddressable
instances that correspond to v2 of the Unison hash function. - Miscellaneous helper functions related to hashing.
Synopsis
- data Branch = Branch {
- terms :: Map NameSegment (Map Referent MdValues)
- types :: Map NameSegment (Map Reference MdValues)
- patches :: Map NameSegment Hash
- children :: Map NameSegment Hash
- data Causal = Causal {
- branchHash :: Hash
- parents :: Set Hash
- data DataDeclaration v a = DataDeclaration {
- modifier :: Modifier
- annotation :: a
- bound :: [v]
- constructors' :: [(a, v, Type v a)]
- type Decl v a = Either (EffectDeclaration v a) (DataDeclaration v a)
- newtype EffectDeclaration v a = EffectDeclaration {
- toDataDecl :: DataDeclaration v a
- data Kind
- data MatchCase loc a = MatchCase (Pattern loc) (Maybe a) a
- newtype MdValues = MdValues (Set MetadataValue)
- data Modifier
- = Structural
- | Unique Text
- newtype NameSegment = NameSegment Text
- data Patch = Patch {}
- data Pattern loc
- = PatternUnbound loc
- | PatternVar loc
- | PatternBoolean loc !Bool
- | PatternInt loc !Int64
- | PatternNat loc !Word64
- | PatternFloat loc !Double
- | PatternText loc !Text
- | PatternChar loc !Char
- | PatternConstructor loc !Reference !ConstructorId [Pattern loc]
- | PatternAs loc (Pattern loc)
- | PatternEffectPure loc (Pattern loc)
- | PatternEffectBind loc !Reference !ConstructorId [Pattern loc] (Pattern loc)
- | PatternSequenceLiteral loc [Pattern loc]
- | PatternSequenceOp loc (Pattern loc) !SeqOp (Pattern loc)
- data Reference
- pattern ReferenceDerived :: Hash -> Pos -> Reference
- data ReferenceId = ReferenceId Hash Pos
- data Referent
- = ReferentRef Reference
- | ReferentCon Reference ConstructorId
- data SeqOp
- type Term v a = Term2 v a a v a
- data TermEdit
- data TermF typeVar typeAnn patternAnn a
- = TermInt Int64
- | TermNat Word64
- | TermFloat Double
- | TermBoolean Bool
- | TermText Text
- | TermChar Char
- | TermBlank (Blank typeAnn)
- | TermRef Reference
- | TermConstructor Reference ConstructorId
- | TermRequest Reference ConstructorId
- | TermHandle a a
- | TermApp a a
- | TermAnn a (Type typeVar typeAnn)
- | TermList (Seq a)
- | TermIf a a a
- | TermAnd a a
- | TermOr a a
- | TermLam a
- | TermLetRec [a] a
- | TermLet a a
- | TermMatch a [MatchCase patternAnn a]
- | TermTermLink Referent
- | TermTypeLink Reference
- type Type v a = Term TypeF v a
- data TypeEdit
- data TypeF a
- = TypeRef Reference
- | TypeArrow a a
- | TypeAnn a Kind
- | TypeApp a a
- | TypeEffect a a
- | TypeEffects [a]
- | TypeForall a
- | TypeIntroOuter a
- hashClosedTerm :: Var v => Term v a -> ReferenceId
- hashDecls :: (Eq v, Var v, Show v) => (v -> Name) -> Map v (DataDeclaration v a) -> ResolutionResult a [(v, ReferenceId, DataDeclaration v a)]
- hashTermComponents :: forall v a extra. Var v => Map v (Term v a, Type v a, extra) -> Map v (ReferenceId, Term v a, Type v a, extra)
- hashTermComponentsWithoutTypes :: Var v => Map v (Term v a) -> Map v (ReferenceId, Term v a)
- typeToReference :: (Ord v, Show v) => Type v a -> Reference
- typeToReferenceMentions :: (Ord v, Show v) => Type v a -> Set Reference
- class ContentAddressable a where
- contentHash :: a -> Hash
Documentation
Branch | |
|
Instances
ContentAddressable Causal Source # | |
Defined in Unison.Hashing.V2.Causal contentHash :: Causal -> Hash # |
data DataDeclaration v a Source #
DataDeclaration | |
|
Instances
Functor (DataDeclaration v) Source # | |
Defined in Unison.Hashing.V2.DataDeclaration fmap :: (a -> b) -> DataDeclaration v a -> DataDeclaration v b # (<$) :: a -> DataDeclaration v b -> DataDeclaration v a # |
type Decl v a = Either (EffectDeclaration v a) (DataDeclaration v a) Source #
newtype EffectDeclaration v a Source #
Instances
Functor (EffectDeclaration v) Source # | |
Defined in Unison.Hashing.V2.DataDeclaration fmap :: (a -> b) -> EffectDeclaration v a -> EffectDeclaration v b # (<$) :: a -> EffectDeclaration v b -> EffectDeclaration v a # |
Instances
Generic Kind Source # | |
Read Kind Source # | |
Show Kind Source # | |
Eq Kind Source # | |
Ord Kind Source # | |
type Rep Kind Source # | |
Defined in Unison.Hashing.V2.Kind type Rep Kind = D1 ('MetaData "Kind" "Unison.Hashing.V2.Kind" "unison-hashing-v2-0.0.0-8U69oGI4KqS9Atr1Yxw2J3" 'False) (C1 ('MetaCons "KindStar" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "KindArrow" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Kind) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Kind))) |
Instances
newtype NameSegment Source #
A name segment.
Instances
Show NameSegment Source # | |
Defined in Unison.Hashing.V2.NameSegment showsPrec :: Int -> NameSegment -> ShowS # show :: NameSegment -> String # showList :: [NameSegment] -> ShowS # | |
Eq NameSegment Source # | |
Defined in Unison.Hashing.V2.NameSegment (==) :: NameSegment -> NameSegment -> Bool # (/=) :: NameSegment -> NameSegment -> Bool # | |
Ord NameSegment Source # | |
Defined in Unison.Hashing.V2.NameSegment compare :: NameSegment -> NameSegment -> Ordering # (<) :: NameSegment -> NameSegment -> Bool # (<=) :: NameSegment -> NameSegment -> Bool # (>) :: NameSegment -> NameSegment -> Bool # (>=) :: NameSegment -> NameSegment -> Bool # max :: NameSegment -> NameSegment -> NameSegment # min :: NameSegment -> NameSegment -> NameSegment # |
Instances
ContentAddressable Patch Source # | |
Defined in Unison.Hashing.V2.Patch contentHash :: Patch -> Hash # |
PatternUnbound loc | |
PatternVar loc | |
PatternBoolean loc !Bool | |
PatternInt loc !Int64 | |
PatternNat loc !Word64 | |
PatternFloat loc !Double | |
PatternText loc !Text | |
PatternChar loc !Char | |
PatternConstructor loc !Reference !ConstructorId [Pattern loc] | |
PatternAs loc (Pattern loc) | |
PatternEffectPure loc (Pattern loc) | |
PatternEffectBind loc !Reference !ConstructorId [Pattern loc] (Pattern loc) | |
PatternSequenceLiteral loc [Pattern loc] | |
PatternSequenceOp loc (Pattern loc) !SeqOp (Pattern loc) |
Instances
Either a builtin or a user defined (hashed) top-level declaration.
Used for both terms and types. Doesn't distinguish between them.
Other used defined things like local variables don't get Reference
s.
pattern ReferenceDerived :: Hash -> Pos -> Reference Source #
data ReferenceId Source #
Pos
is a position into a cycle of size Size
, as cycles are hashed together.
ReferenceId Hash Pos |
Instances
Show ReferenceId Source # | |
Defined in Unison.Hashing.V2.Reference showsPrec :: Int -> ReferenceId -> ShowS # show :: ReferenceId -> String # showList :: [ReferenceId] -> ShowS # | |
Eq ReferenceId Source # | |
Defined in Unison.Hashing.V2.Reference (==) :: ReferenceId -> ReferenceId -> Bool # (/=) :: ReferenceId -> ReferenceId -> Bool # | |
Ord ReferenceId Source # | |
Defined in Unison.Hashing.V2.Reference compare :: ReferenceId -> ReferenceId -> Ordering # (<) :: ReferenceId -> ReferenceId -> Bool # (<=) :: ReferenceId -> ReferenceId -> Bool # (>) :: ReferenceId -> ReferenceId -> Bool # (>=) :: ReferenceId -> ReferenceId -> Bool # max :: ReferenceId -> ReferenceId -> ReferenceId # min :: ReferenceId -> ReferenceId -> ReferenceId # |
ReferentRef Reference | |
ReferentCon Reference ConstructorId |
Instances
Generic SeqOp Source # | |
Show SeqOp Source # | |
Eq SeqOp Source # | |
Ord SeqOp Source # | |
type Rep SeqOp Source # | |
Defined in Unison.Hashing.V2.Pattern type Rep SeqOp = D1 ('MetaData "SeqOp" "Unison.Hashing.V2.Pattern" "unison-hashing-v2-0.0.0-8U69oGI4KqS9Atr1Yxw2J3" 'False) (C1 ('MetaCons "Cons" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "Snoc" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Concat" 'PrefixI 'False) (U1 :: Type -> Type))) |
type Term v a = Term2 v a a v a Source #
Like `Term v`, but with an annotation of type a
at every level in the tree
data TermF typeVar typeAnn patternAnn a Source #
Base functor for terms in the Unison language
We need typeVar
because the term and type variables may differ.
TermInt Int64 | |
TermNat Word64 | |
TermFloat Double | |
TermBoolean Bool | |
TermText Text | |
TermChar Char | |
TermBlank (Blank typeAnn) | |
TermRef Reference | |
TermConstructor Reference ConstructorId | |
TermRequest Reference ConstructorId | |
TermHandle a a | |
TermApp a a | |
TermAnn a (Type typeVar typeAnn) | |
TermList (Seq a) | |
TermIf a a a | |
TermAnd a a | |
TermOr a a | |
TermLam a | |
TermLetRec [a] a | |
TermLet a a | |
TermMatch a [MatchCase patternAnn a] | |
TermTermLink Referent | |
TermTypeLink Reference |
Instances
type Type v a = Term TypeF v a Source #
Types are represented as ABTs over the base functor F, with variables in v
Base functor for types in the Unison language
TypeRef Reference | |
TypeArrow a a | |
TypeAnn a Kind | |
TypeApp a a | |
TypeEffect a a | |
TypeEffects [a] | |
TypeForall a | |
TypeIntroOuter a |
Instances
Foldable TypeF Source # | |
Defined in Unison.Hashing.V2.Type fold :: Monoid m => TypeF m -> m # foldMap :: Monoid m => (a -> m) -> TypeF a -> m # foldMap' :: Monoid m => (a -> m) -> TypeF a -> m # foldr :: (a -> b -> b) -> b -> TypeF a -> b # foldr' :: (a -> b -> b) -> b -> TypeF a -> b # foldl :: (b -> a -> b) -> b -> TypeF a -> b # foldl' :: (b -> a -> b) -> b -> TypeF a -> b # foldr1 :: (a -> a -> a) -> TypeF a -> a # foldl1 :: (a -> a -> a) -> TypeF a -> a # elem :: Eq a => a -> TypeF a -> Bool # maximum :: Ord a => TypeF a -> a # minimum :: Ord a => TypeF a -> a # | |
Traversable TypeF Source # | |
Functor TypeF Source # | |
hashClosedTerm :: Var v => Term v a -> ReferenceId Source #
hashDecls :: (Eq v, Var v, Show v) => (v -> Name) -> Map v (DataDeclaration v a) -> ResolutionResult a [(v, ReferenceId, DataDeclaration v a)] Source #
compute the hashes of these user defined types and update any free vars corresponding to these decls with the resulting hashes
data List a = Nil | Cons a (List a) becomes something like (List, #xyz, [forall a. #xyz a, forall a. a -> (#xyz a) -> (#xyz a)])
NOTE: technical limitation, this implementation gives diff results if ctors have the same FQN as one of the types. TODO: assert this and bomb if not satisfied, or else do local mangling and unmangling to ensure this doesn't affect the hash.
hashTermComponents :: forall v a extra. Var v => Map v (Term v a, Type v a, extra) -> Map v (ReferenceId, Term v a, Type v a, extra) Source #
hashTermComponentsWithoutTypes :: Var v => Map v (Term v a) -> Map v (ReferenceId, Term v a) Source #
Re-exports
class ContentAddressable a where #
A type class that is inhabited by types that can compute a hash of their content.
The base instances of this class should only live in dedicated "hashing packages" such as unison-hashing-v2
, whose
types and implementations should never change.
Trivial wrapper instances can be written around these, but note these pipelines from
MyType ==> SomeHashingType ==> Hash
must take care not to change the MyType ==> SomeHashingType
conversion, once
written.
For example, we might have a representation of some namespace in memory
data Namespace = Namespace Terms Types OtherStuff CachesAndWhatnot
with a somewhat equivalent "hashing" type in some "hashing package", with a ContentAddressable instance
data HashingNamespace = Namespace Terms Types
We can of course make our own convenience instance
instance ContentAddressable Namespace where contentHash = contentHash . namespaceToHashingNamespace
But we must make sure that the implementation of namespaceToHashingNamespace
never changes the fields in the
corresponding HashingNamespace
, even as features are added to or removed from Namespace
.
contentHash :: a -> Hash #
Instances
ContentAddressable Branch Source # | |
Defined in Unison.Hashing.V2.Branch contentHash :: Branch -> Hash # | |
ContentAddressable Causal Source # | |
Defined in Unison.Hashing.V2.Causal contentHash :: Causal -> Hash # | |
ContentAddressable Patch Source # | |
Defined in Unison.Hashing.V2.Patch contentHash :: Patch -> Hash # |