wip refactoring Reference to allow a Ref to refer to a cycle

This commit is contained in:
Paul Chiusano 2018-10-24 10:13:29 -04:00
parent 55aafdc237
commit f94330b0a5
3 changed files with 26 additions and 1 deletions

View File

@ -21,7 +21,7 @@ import qualified Unison.ABT as ABT
import qualified Unison.Blank as Blank
import qualified Unison.DataDeclaration as DD
import qualified Unison.Hash as Hash
import Unison.Reference
import Unison.Reference (Reference(..))
import Unison.Term
import qualified Unison.Typechecker.Components as Components
import Unison.UnisonFile (UnisonFile(..))

View File

@ -20,6 +20,7 @@ import qualified Unison.Reference as Reference
import Unison.Type (AnnotatedType)
import qualified Unison.Type as Type
import Unison.Var (Var)
import Unison.Hash (Hash)
type DataDeclaration v = DataDeclaration' v ()
@ -132,6 +133,15 @@ fromABT (ABT.AbsN' bound (
[((), v, unsafeUnwrapType t) | (v, t) <- names `zip` stuff]
fromABT a = error $ "ABT not of correct form to convert to DataDeclaration: " ++ show a
hashDecls2
:: (Eq v, Var v)
=> Map v (DataDeclaration' v a)
-> [(Hash, [v])]
hashDecls2 decls = fixup <$> ABT.hashComponents mkRef (toABT . void <$> decls)
where mkRef h i = ABT.tm (Type (Type.Ref (Reference.Derived h)))
fixup (h, scc) = (h, fst <$> scc)
-- use this to impl hashDecls
-- Implementation detail of `hashDecls`, works with unannotated data decls
hashDecls0
:: (Eq v, Var v)

View File

@ -6,11 +6,26 @@ import GHC.Generics
import Unison.Hashable as Hashable
import qualified Data.Text as Text
import qualified Unison.Hash as H
import Data.Word (Word64)
-- could add a `Word` parameter to `Derived`
-- associated with each hash would actually be a list of terms / type decls
data Reference = Builtin Text.Text | Derived H.Hash deriving (Eq,Ord,Generic)
type Pos = Word64
type Size = Word64
derived :: H.Hash -> Pos -> Size -> Reference
derived _h _pos _size = error "todo"
component :: H.Hash -> [k] -> [(k, Reference)]
component h ks = let
size = fromIntegral (length ks)
in [ (k, derived h i size) | (k, i) <- ks `zip` [0..]]
components :: [(H.Hash, [k])] -> [[(k, Reference)]]
components sccs = uncurry component <$> sccs
instance Show Reference where
show (Builtin t) = Text.unpack t
show (Derived h) = "#" <> show h