{-# LANGUAGE RecordWildCards #-}
module Unison.DataDeclaration
( DataDeclaration (..),
EffectDeclaration (..),
Decl,
DeclOrBuiltin (..),
Modifier (..),
allVars,
asDataDecl,
bindReferences,
constructorCount,
constructorNames,
constructors,
constructorType,
constructorTypes,
constructorVars,
constructorIds,
declConstructorReferents,
declTypeDependencies,
labeledDeclTypeDependencies,
labeledDeclDependenciesIncludingSelf,
declFields,
typeDependencies,
labeledTypeDependencies,
unhashComponent,
mkDataDecl',
mkEffectDecl',
typeOfConstructor,
withEffectDeclM,
amap,
updateDependencies,
constructors_,
asDataDecl_,
declAsDataDecl_,
setConstructorNames,
)
where
import Control.Lens (Iso', Lens', imap, iso, lens, _2, _3)
import Control.Monad.State (evalState)
import Data.Map qualified as Map
import Data.Set qualified as Set
import Unison.ABT qualified as ABT
import Unison.ConstructorReference (GConstructorReference (..))
import Unison.ConstructorType qualified as CT
import Unison.DataDeclaration.ConstructorId (ConstructorId)
import Unison.LabeledDependency qualified as LD
import Unison.Name qualified as Name
import Unison.Names.ResolutionResult qualified as Names
import Unison.Prelude
import Unison.Reference (Reference, TypeReference)
import Unison.Reference qualified as Reference
import Unison.Referent qualified as Referent
import Unison.ReferentPrime qualified as Referent'
import Unison.Type (Type)
import Unison.Type qualified as Type
import Unison.Var (Var)
import Unison.Var qualified as Var
import Prelude hiding (cycle)
type Decl v a = Either (EffectDeclaration v a) (DataDeclaration v a)
data DeclOrBuiltin v a
= Builtin CT.ConstructorType
| Decl (Decl v a)
deriving (DeclOrBuiltin v a -> DeclOrBuiltin v a -> Bool
(DeclOrBuiltin v a -> DeclOrBuiltin v a -> Bool)
-> (DeclOrBuiltin v a -> DeclOrBuiltin v a -> Bool)
-> Eq (DeclOrBuiltin v a)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall v a.
(Var v, Eq a) =>
DeclOrBuiltin v a -> DeclOrBuiltin v a -> Bool
$c== :: forall v a.
(Var v, Eq a) =>
DeclOrBuiltin v a -> DeclOrBuiltin v a -> Bool
== :: DeclOrBuiltin v a -> DeclOrBuiltin v a -> Bool
$c/= :: forall v a.
(Var v, Eq a) =>
DeclOrBuiltin v a -> DeclOrBuiltin v a -> Bool
/= :: DeclOrBuiltin v a -> DeclOrBuiltin v a -> Bool
Eq, Eq (DeclOrBuiltin v a)
Eq (DeclOrBuiltin v a) =>
(DeclOrBuiltin v a -> DeclOrBuiltin v a -> Ordering)
-> (DeclOrBuiltin v a -> DeclOrBuiltin v a -> Bool)
-> (DeclOrBuiltin v a -> DeclOrBuiltin v a -> Bool)
-> (DeclOrBuiltin v a -> DeclOrBuiltin v a -> Bool)
-> (DeclOrBuiltin v a -> DeclOrBuiltin v a -> Bool)
-> (DeclOrBuiltin v a -> DeclOrBuiltin v a -> DeclOrBuiltin v a)
-> (DeclOrBuiltin v a -> DeclOrBuiltin v a -> DeclOrBuiltin v a)
-> Ord (DeclOrBuiltin v a)
DeclOrBuiltin v a -> DeclOrBuiltin v a -> Bool
DeclOrBuiltin v a -> DeclOrBuiltin v a -> Ordering
DeclOrBuiltin v a -> DeclOrBuiltin v a -> DeclOrBuiltin v a
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall v a. (Var v, Ord a) => Eq (DeclOrBuiltin v a)
forall v a.
(Var v, Ord a) =>
DeclOrBuiltin v a -> DeclOrBuiltin v a -> Bool
forall v a.
(Var v, Ord a) =>
DeclOrBuiltin v a -> DeclOrBuiltin v a -> Ordering
forall v a.
(Var v, Ord a) =>
DeclOrBuiltin v a -> DeclOrBuiltin v a -> DeclOrBuiltin v a
$ccompare :: forall v a.
(Var v, Ord a) =>
DeclOrBuiltin v a -> DeclOrBuiltin v a -> Ordering
compare :: DeclOrBuiltin v a -> DeclOrBuiltin v a -> Ordering
$c< :: forall v a.
(Var v, Ord a) =>
DeclOrBuiltin v a -> DeclOrBuiltin v a -> Bool
< :: DeclOrBuiltin v a -> DeclOrBuiltin v a -> Bool
$c<= :: forall v a.
(Var v, Ord a) =>
DeclOrBuiltin v a -> DeclOrBuiltin v a -> Bool
<= :: DeclOrBuiltin v a -> DeclOrBuiltin v a -> Bool
$c> :: forall v a.
(Var v, Ord a) =>
DeclOrBuiltin v a -> DeclOrBuiltin v a -> Bool
> :: DeclOrBuiltin v a -> DeclOrBuiltin v a -> Bool
$c>= :: forall v a.
(Var v, Ord a) =>
DeclOrBuiltin v a -> DeclOrBuiltin v a -> Bool
>= :: DeclOrBuiltin v a -> DeclOrBuiltin v a -> Bool
$cmax :: forall v a.
(Var v, Ord a) =>
DeclOrBuiltin v a -> DeclOrBuiltin v a -> DeclOrBuiltin v a
max :: DeclOrBuiltin v a -> DeclOrBuiltin v a -> DeclOrBuiltin v a
$cmin :: forall v a.
(Var v, Ord a) =>
DeclOrBuiltin v a -> DeclOrBuiltin v a -> DeclOrBuiltin v a
min :: DeclOrBuiltin v a -> DeclOrBuiltin v a -> DeclOrBuiltin v a
Ord, Int -> DeclOrBuiltin v a -> ShowS
[DeclOrBuiltin v a] -> ShowS
DeclOrBuiltin v a -> String
(Int -> DeclOrBuiltin v a -> ShowS)
-> (DeclOrBuiltin v a -> String)
-> ([DeclOrBuiltin v a] -> ShowS)
-> Show (DeclOrBuiltin v a)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall v a. (Show a, Show v) => Int -> DeclOrBuiltin v a -> ShowS
forall v a. (Show a, Show v) => [DeclOrBuiltin v a] -> ShowS
forall v a. (Show a, Show v) => DeclOrBuiltin v a -> String
$cshowsPrec :: forall v a. (Show a, Show v) => Int -> DeclOrBuiltin v a -> ShowS
showsPrec :: Int -> DeclOrBuiltin v a -> ShowS
$cshow :: forall v a. (Show a, Show v) => DeclOrBuiltin v a -> String
show :: DeclOrBuiltin v a -> String
$cshowList :: forall v a. (Show a, Show v) => [DeclOrBuiltin v a] -> ShowS
showList :: [DeclOrBuiltin v a] -> ShowS
Show)
asDataDecl :: Decl v a -> DataDeclaration v a
asDataDecl :: forall v a. Decl v a -> DataDeclaration v a
asDataDecl = (EffectDeclaration v a -> DataDeclaration v a)
-> (DataDeclaration v a -> DataDeclaration v a)
-> Either (EffectDeclaration v a) (DataDeclaration v a)
-> DataDeclaration v a
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either EffectDeclaration v a -> DataDeclaration v a
forall v a. EffectDeclaration v a -> DataDeclaration v a
toDataDecl DataDeclaration v a -> DataDeclaration v a
forall a. a -> a
id
declTypeDependencies :: (Ord v) => Decl v a -> Set Reference
declTypeDependencies :: forall v a. Ord v => Decl v a -> Set Reference
declTypeDependencies = (EffectDeclaration v a -> Set Reference)
-> (DataDeclaration v a -> Set Reference)
-> Either (EffectDeclaration v a) (DataDeclaration v a)
-> Set Reference
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (DataDeclaration v a -> Set Reference
forall v a. Ord v => DataDeclaration v a -> Set Reference
typeDependencies (DataDeclaration v a -> Set Reference)
-> (EffectDeclaration v a -> DataDeclaration v a)
-> EffectDeclaration v a
-> Set Reference
forall b c a. (b -> c) -> (a -> b) -> a -> c
. EffectDeclaration v a -> DataDeclaration v a
forall v a. EffectDeclaration v a -> DataDeclaration v a
toDataDecl) DataDeclaration v a -> Set Reference
forall v a. Ord v => DataDeclaration v a -> Set Reference
typeDependencies
labeledDeclTypeDependencies :: (Ord v) => Decl v a -> Set LD.LabeledDependency
labeledDeclTypeDependencies :: forall v a. Ord v => Decl v a -> Set LabeledDependency
labeledDeclTypeDependencies = (Reference -> LabeledDependency)
-> Set Reference -> Set LabeledDependency
forall b a. Ord b => (a -> b) -> Set a -> Set b
Set.map Reference -> LabeledDependency
LD.TypeReference (Set Reference -> Set LabeledDependency)
-> (Decl v a -> Set Reference) -> Decl v a -> Set LabeledDependency
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Decl v a -> Set Reference
forall v a. Ord v => Decl v a -> Set Reference
declTypeDependencies
labeledDeclDependenciesIncludingSelf :: (Ord v) => Reference.TypeReference -> Decl v a -> Set LD.LabeledDependency
labeledDeclDependenciesIncludingSelf :: forall v a. Ord v => Reference -> Decl v a -> Set LabeledDependency
labeledDeclDependenciesIncludingSelf Reference
selfRef Decl v a
decl =
Decl v a -> Set LabeledDependency
forall v a. Ord v => Decl v a -> Set LabeledDependency
labeledDeclTypeDependencies Decl v a
decl Set LabeledDependency
-> Set LabeledDependency -> Set LabeledDependency
forall a. Semigroup a => a -> a -> a
<> (LabeledDependency -> Set LabeledDependency
forall a. a -> Set a
Set.singleton (LabeledDependency -> Set LabeledDependency)
-> LabeledDependency -> Set LabeledDependency
forall a b. (a -> b) -> a -> b
$ Reference -> LabeledDependency
LD.TypeReference Reference
selfRef) Set LabeledDependency
-> Set LabeledDependency -> Set LabeledDependency
forall a. Semigroup a => a -> a -> a
<> Set LabeledDependency
labeledConstructorRefs
where
labeledConstructorRefs :: Set LD.LabeledDependency
labeledConstructorRefs :: Set LabeledDependency
labeledConstructorRefs =
case Reference
selfRef of
Reference.Builtin {} -> Set LabeledDependency
forall a. Monoid a => a
mempty
Reference.DerivedId Id' Hash
selfRefId ->
Id' Hash -> Decl v a -> [Id]
forall v a. Id' Hash -> Decl v a -> [Id]
declConstructorReferents Id' Hash
selfRefId Decl v a
decl
[Id] -> ([Id] -> [LabeledDependency]) -> [LabeledDependency]
forall a b. a -> (a -> b) -> b
& (Id -> LabeledDependency) -> [Id] -> [LabeledDependency]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Referent -> LabeledDependency
LD.TermReferent (Referent -> LabeledDependency)
-> (Id -> Referent) -> Id -> LabeledDependency
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Id' Hash -> Reference) -> Id -> Referent
forall a b. (a -> b) -> Referent' a -> Referent' b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Id' Hash -> Reference
forall h t. Id' h -> Reference' t h
Reference.DerivedId)
[LabeledDependency]
-> ([LabeledDependency] -> Set LabeledDependency)
-> Set LabeledDependency
forall a b. a -> (a -> b) -> b
& [LabeledDependency] -> Set LabeledDependency
forall a. Ord a => [a] -> Set a
Set.fromList
constructorType :: Decl v a -> CT.ConstructorType
constructorType :: forall v a. Decl v a -> ConstructorType
constructorType = \case
Left {} -> ConstructorType
CT.Effect
Right {} -> ConstructorType
CT.Data
data Modifier = Structural | Unique Text
deriving (Modifier -> Modifier -> Bool
(Modifier -> Modifier -> Bool)
-> (Modifier -> Modifier -> Bool) -> Eq Modifier
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Modifier -> Modifier -> Bool
== :: Modifier -> Modifier -> Bool
$c/= :: Modifier -> Modifier -> Bool
/= :: Modifier -> Modifier -> Bool
Eq, Eq Modifier
Eq Modifier =>
(Modifier -> Modifier -> Ordering)
-> (Modifier -> Modifier -> Bool)
-> (Modifier -> Modifier -> Bool)
-> (Modifier -> Modifier -> Bool)
-> (Modifier -> Modifier -> Bool)
-> (Modifier -> Modifier -> Modifier)
-> (Modifier -> Modifier -> Modifier)
-> Ord Modifier
Modifier -> Modifier -> Bool
Modifier -> Modifier -> Ordering
Modifier -> Modifier -> Modifier
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: Modifier -> Modifier -> Ordering
compare :: Modifier -> Modifier -> Ordering
$c< :: Modifier -> Modifier -> Bool
< :: Modifier -> Modifier -> Bool
$c<= :: Modifier -> Modifier -> Bool
<= :: Modifier -> Modifier -> Bool
$c> :: Modifier -> Modifier -> Bool
> :: Modifier -> Modifier -> Bool
$c>= :: Modifier -> Modifier -> Bool
>= :: Modifier -> Modifier -> Bool
$cmax :: Modifier -> Modifier -> Modifier
max :: Modifier -> Modifier -> Modifier
$cmin :: Modifier -> Modifier -> Modifier
min :: Modifier -> Modifier -> Modifier
Ord, Int -> Modifier -> ShowS
[Modifier] -> ShowS
Modifier -> String
(Int -> Modifier -> ShowS)
-> (Modifier -> String) -> ([Modifier] -> ShowS) -> Show Modifier
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Modifier -> ShowS
showsPrec :: Int -> Modifier -> ShowS
$cshow :: Modifier -> String
show :: Modifier -> String
$cshowList :: [Modifier] -> ShowS
showList :: [Modifier] -> ShowS
Show)
data DataDeclaration v a = DataDeclaration
{ forall v a. DataDeclaration v a -> Modifier
modifier :: Modifier,
forall v a. DataDeclaration v a -> a
annotation :: a,
forall v a. DataDeclaration v a -> [v]
bound :: [v],
forall v a. DataDeclaration v a -> [(a, v, Type v a)]
constructors' :: [(a, v, Type v a)]
}
deriving (DataDeclaration v a -> DataDeclaration v a -> Bool
(DataDeclaration v a -> DataDeclaration v a -> Bool)
-> (DataDeclaration v a -> DataDeclaration v a -> Bool)
-> Eq (DataDeclaration v a)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall v a.
(Eq a, Var v) =>
DataDeclaration v a -> DataDeclaration v a -> Bool
$c== :: forall v a.
(Eq a, Var v) =>
DataDeclaration v a -> DataDeclaration v a -> Bool
== :: DataDeclaration v a -> DataDeclaration v a -> Bool
$c/= :: forall v a.
(Eq a, Var v) =>
DataDeclaration v a -> DataDeclaration v a -> Bool
/= :: DataDeclaration v a -> DataDeclaration v a -> Bool
Eq, Eq (DataDeclaration v a)
Eq (DataDeclaration v a) =>
(DataDeclaration v a -> DataDeclaration v a -> Ordering)
-> (DataDeclaration v a -> DataDeclaration v a -> Bool)
-> (DataDeclaration v a -> DataDeclaration v a -> Bool)
-> (DataDeclaration v a -> DataDeclaration v a -> Bool)
-> (DataDeclaration v a -> DataDeclaration v a -> Bool)
-> (DataDeclaration v a
-> DataDeclaration v a -> DataDeclaration v a)
-> (DataDeclaration v a
-> DataDeclaration v a -> DataDeclaration v a)
-> Ord (DataDeclaration v a)
DataDeclaration v a -> DataDeclaration v a -> Bool
DataDeclaration v a -> DataDeclaration v a -> Ordering
DataDeclaration v a -> DataDeclaration v a -> DataDeclaration v a
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall v a. (Var v, Ord a) => Eq (DataDeclaration v a)
forall v a.
(Var v, Ord a) =>
DataDeclaration v a -> DataDeclaration v a -> Bool
forall v a.
(Var v, Ord a) =>
DataDeclaration v a -> DataDeclaration v a -> Ordering
forall v a.
(Var v, Ord a) =>
DataDeclaration v a -> DataDeclaration v a -> DataDeclaration v a
$ccompare :: forall v a.
(Var v, Ord a) =>
DataDeclaration v a -> DataDeclaration v a -> Ordering
compare :: DataDeclaration v a -> DataDeclaration v a -> Ordering
$c< :: forall v a.
(Var v, Ord a) =>
DataDeclaration v a -> DataDeclaration v a -> Bool
< :: DataDeclaration v a -> DataDeclaration v a -> Bool
$c<= :: forall v a.
(Var v, Ord a) =>
DataDeclaration v a -> DataDeclaration v a -> Bool
<= :: DataDeclaration v a -> DataDeclaration v a -> Bool
$c> :: forall v a.
(Var v, Ord a) =>
DataDeclaration v a -> DataDeclaration v a -> Bool
> :: DataDeclaration v a -> DataDeclaration v a -> Bool
$c>= :: forall v a.
(Var v, Ord a) =>
DataDeclaration v a -> DataDeclaration v a -> Bool
>= :: DataDeclaration v a -> DataDeclaration v a -> Bool
$cmax :: forall v a.
(Var v, Ord a) =>
DataDeclaration v a -> DataDeclaration v a -> DataDeclaration v a
max :: DataDeclaration v a -> DataDeclaration v a -> DataDeclaration v a
$cmin :: forall v a.
(Var v, Ord a) =>
DataDeclaration v a -> DataDeclaration v a -> DataDeclaration v a
min :: DataDeclaration v a -> DataDeclaration v a -> DataDeclaration v a
Ord, Int -> DataDeclaration v a -> ShowS
[DataDeclaration v a] -> ShowS
DataDeclaration v a -> String
(Int -> DataDeclaration v a -> ShowS)
-> (DataDeclaration v a -> String)
-> ([DataDeclaration v a] -> ShowS)
-> Show (DataDeclaration v a)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall v a. (Show a, Show v) => Int -> DataDeclaration v a -> ShowS
forall v a. (Show a, Show v) => [DataDeclaration v a] -> ShowS
forall v a. (Show a, Show v) => DataDeclaration v a -> String
$cshowsPrec :: forall v a. (Show a, Show v) => Int -> DataDeclaration v a -> ShowS
showsPrec :: Int -> DataDeclaration v a -> ShowS
$cshow :: forall v a. (Show a, Show v) => DataDeclaration v a -> String
show :: DataDeclaration v a -> String
$cshowList :: forall v a. (Show a, Show v) => [DataDeclaration v a] -> ShowS
showList :: [DataDeclaration v a] -> ShowS
Show, (forall a b.
(a -> b) -> DataDeclaration v a -> DataDeclaration v b)
-> (forall a b. a -> DataDeclaration v b -> DataDeclaration v a)
-> Functor (DataDeclaration v)
forall a b. a -> DataDeclaration v b -> DataDeclaration v a
forall a b. (a -> b) -> DataDeclaration v a -> DataDeclaration v b
forall v a b. a -> DataDeclaration v b -> DataDeclaration v a
forall v a b.
(a -> b) -> DataDeclaration v a -> DataDeclaration v b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall v a b.
(a -> b) -> DataDeclaration v a -> DataDeclaration v b
fmap :: forall a b. (a -> b) -> DataDeclaration v a -> DataDeclaration v b
$c<$ :: forall v a b. a -> DataDeclaration v b -> DataDeclaration v a
<$ :: forall a b. a -> DataDeclaration v b -> DataDeclaration v a
Functor, (forall x. DataDeclaration v a -> Rep (DataDeclaration v a) x)
-> (forall x. Rep (DataDeclaration v a) x -> DataDeclaration v a)
-> Generic (DataDeclaration v a)
forall x. Rep (DataDeclaration v a) x -> DataDeclaration v a
forall x. DataDeclaration v a -> Rep (DataDeclaration v a) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall v a x. Rep (DataDeclaration v a) x -> DataDeclaration v a
forall v a x. DataDeclaration v a -> Rep (DataDeclaration v a) x
$cfrom :: forall v a x. DataDeclaration v a -> Rep (DataDeclaration v a) x
from :: forall x. DataDeclaration v a -> Rep (DataDeclaration v a) x
$cto :: forall v a x. Rep (DataDeclaration v a) x -> DataDeclaration v a
to :: forall x. Rep (DataDeclaration v a) x -> DataDeclaration v a
Generic)
constructorCount :: DataDeclaration v a -> Int
constructorCount :: forall v a. DataDeclaration v a -> Int
constructorCount DataDeclaration {[(a, v, Type v a)]
$sel:constructors':DataDeclaration :: forall v a. DataDeclaration v a -> [(a, v, Type v a)]
constructors' :: [(a, v, Type v a)]
constructors'} = [(a, v, Type v a)] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [(a, v, Type v a)]
constructors'
constructors_ :: Lens' (DataDeclaration v a) [(a, v, Type v a)]
constructors_ :: forall v a (f :: * -> *).
Functor f =>
([(a, v, Type v a)] -> f [(a, v, Type v a)])
-> DataDeclaration v a -> f (DataDeclaration v a)
constructors_ = (DataDeclaration v a -> [(a, v, Type v a)])
-> (DataDeclaration v a
-> [(a, v, Type v a)] -> DataDeclaration v a)
-> Lens
(DataDeclaration v a)
(DataDeclaration v a)
[(a, v, Type v a)]
[(a, v, Type v a)]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens DataDeclaration v a -> [(a, v, Type v a)]
forall v a. DataDeclaration v a -> [(a, v, Type v a)]
getter DataDeclaration v a -> [(a, v, Type v a)] -> DataDeclaration v a
forall {v} {a}.
DataDeclaration v a -> [(a, v, Type v a)] -> DataDeclaration v a
setter
where
getter :: DataDeclaration v a -> [(a, v, Type v a)]
getter = DataDeclaration v a -> [(a, v, Type v a)]
forall v a. DataDeclaration v a -> [(a, v, Type v a)]
constructors'
setter :: DataDeclaration v a -> [(a, v, Type v a)] -> DataDeclaration v a
setter DataDeclaration v a
dd [(a, v, Type v a)]
ctors = DataDeclaration v a
dd {constructors' = ctors}
newtype EffectDeclaration v a = EffectDeclaration
{ forall v a. EffectDeclaration v a -> DataDeclaration v a
toDataDecl :: DataDeclaration v a
}
deriving (EffectDeclaration v a -> EffectDeclaration v a -> Bool
(EffectDeclaration v a -> EffectDeclaration v a -> Bool)
-> (EffectDeclaration v a -> EffectDeclaration v a -> Bool)
-> Eq (EffectDeclaration v a)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall v a.
(Var v, Eq a) =>
EffectDeclaration v a -> EffectDeclaration v a -> Bool
$c== :: forall v a.
(Var v, Eq a) =>
EffectDeclaration v a -> EffectDeclaration v a -> Bool
== :: EffectDeclaration v a -> EffectDeclaration v a -> Bool
$c/= :: forall v a.
(Var v, Eq a) =>
EffectDeclaration v a -> EffectDeclaration v a -> Bool
/= :: EffectDeclaration v a -> EffectDeclaration v a -> Bool
Eq, Eq (EffectDeclaration v a)
Eq (EffectDeclaration v a) =>
(EffectDeclaration v a -> EffectDeclaration v a -> Ordering)
-> (EffectDeclaration v a -> EffectDeclaration v a -> Bool)
-> (EffectDeclaration v a -> EffectDeclaration v a -> Bool)
-> (EffectDeclaration v a -> EffectDeclaration v a -> Bool)
-> (EffectDeclaration v a -> EffectDeclaration v a -> Bool)
-> (EffectDeclaration v a
-> EffectDeclaration v a -> EffectDeclaration v a)
-> (EffectDeclaration v a
-> EffectDeclaration v a -> EffectDeclaration v a)
-> Ord (EffectDeclaration v a)
EffectDeclaration v a -> EffectDeclaration v a -> Bool
EffectDeclaration v a -> EffectDeclaration v a -> Ordering
EffectDeclaration v a
-> EffectDeclaration v a -> EffectDeclaration v a
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall v a. (Var v, Ord a) => Eq (EffectDeclaration v a)
forall v a.
(Var v, Ord a) =>
EffectDeclaration v a -> EffectDeclaration v a -> Bool
forall v a.
(Var v, Ord a) =>
EffectDeclaration v a -> EffectDeclaration v a -> Ordering
forall v a.
(Var v, Ord a) =>
EffectDeclaration v a
-> EffectDeclaration v a -> EffectDeclaration v a
$ccompare :: forall v a.
(Var v, Ord a) =>
EffectDeclaration v a -> EffectDeclaration v a -> Ordering
compare :: EffectDeclaration v a -> EffectDeclaration v a -> Ordering
$c< :: forall v a.
(Var v, Ord a) =>
EffectDeclaration v a -> EffectDeclaration v a -> Bool
< :: EffectDeclaration v a -> EffectDeclaration v a -> Bool
$c<= :: forall v a.
(Var v, Ord a) =>
EffectDeclaration v a -> EffectDeclaration v a -> Bool
<= :: EffectDeclaration v a -> EffectDeclaration v a -> Bool
$c> :: forall v a.
(Var v, Ord a) =>
EffectDeclaration v a -> EffectDeclaration v a -> Bool
> :: EffectDeclaration v a -> EffectDeclaration v a -> Bool
$c>= :: forall v a.
(Var v, Ord a) =>
EffectDeclaration v a -> EffectDeclaration v a -> Bool
>= :: EffectDeclaration v a -> EffectDeclaration v a -> Bool
$cmax :: forall v a.
(Var v, Ord a) =>
EffectDeclaration v a
-> EffectDeclaration v a -> EffectDeclaration v a
max :: EffectDeclaration v a
-> EffectDeclaration v a -> EffectDeclaration v a
$cmin :: forall v a.
(Var v, Ord a) =>
EffectDeclaration v a
-> EffectDeclaration v a -> EffectDeclaration v a
min :: EffectDeclaration v a
-> EffectDeclaration v a -> EffectDeclaration v a
Ord, Int -> EffectDeclaration v a -> ShowS
[EffectDeclaration v a] -> ShowS
EffectDeclaration v a -> String
(Int -> EffectDeclaration v a -> ShowS)
-> (EffectDeclaration v a -> String)
-> ([EffectDeclaration v a] -> ShowS)
-> Show (EffectDeclaration v a)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall v a.
(Show a, Show v) =>
Int -> EffectDeclaration v a -> ShowS
forall v a. (Show a, Show v) => [EffectDeclaration v a] -> ShowS
forall v a. (Show a, Show v) => EffectDeclaration v a -> String
$cshowsPrec :: forall v a.
(Show a, Show v) =>
Int -> EffectDeclaration v a -> ShowS
showsPrec :: Int -> EffectDeclaration v a -> ShowS
$cshow :: forall v a. (Show a, Show v) => EffectDeclaration v a -> String
show :: EffectDeclaration v a -> String
$cshowList :: forall v a. (Show a, Show v) => [EffectDeclaration v a] -> ShowS
showList :: [EffectDeclaration v a] -> ShowS
Show, (forall a b.
(a -> b) -> EffectDeclaration v a -> EffectDeclaration v b)
-> (forall a b.
a -> EffectDeclaration v b -> EffectDeclaration v a)
-> Functor (EffectDeclaration v)
forall a b. a -> EffectDeclaration v b -> EffectDeclaration v a
forall a b.
(a -> b) -> EffectDeclaration v a -> EffectDeclaration v b
forall v a b. a -> EffectDeclaration v b -> EffectDeclaration v a
forall v a b.
(a -> b) -> EffectDeclaration v a -> EffectDeclaration v b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall v a b.
(a -> b) -> EffectDeclaration v a -> EffectDeclaration v b
fmap :: forall a b.
(a -> b) -> EffectDeclaration v a -> EffectDeclaration v b
$c<$ :: forall v a b. a -> EffectDeclaration v b -> EffectDeclaration v a
<$ :: forall a b. a -> EffectDeclaration v b -> EffectDeclaration v a
Functor)
declAsDataDecl_ :: Lens' (Decl v a) (DataDeclaration v a)
declAsDataDecl_ :: forall v a (f :: * -> *).
Functor f =>
(DataDeclaration v a -> f (DataDeclaration v a))
-> Decl v a -> f (Decl v a)
declAsDataDecl_ = (Decl v a -> DataDeclaration v a)
-> (Decl v a -> DataDeclaration v a -> Decl v a)
-> Lens
(Decl v a) (Decl v a) (DataDeclaration v a) (DataDeclaration v a)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens Decl v a -> DataDeclaration v a
forall v a. Decl v a -> DataDeclaration v a
get Decl v a -> DataDeclaration v a -> Decl v a
forall {p :: * -> * -> *} {a} {c} {v} {a}.
Bifunctor p =>
p a c
-> DataDeclaration v a
-> p (EffectDeclaration v a) (DataDeclaration v a)
set
where
get :: Either (EffectDeclaration v a) (DataDeclaration v a)
-> DataDeclaration v a
get (Left EffectDeclaration v a
ed) = EffectDeclaration v a -> DataDeclaration v a
forall v a. EffectDeclaration v a -> DataDeclaration v a
toDataDecl EffectDeclaration v a
ed
get (Right DataDeclaration v a
dd) = DataDeclaration v a
dd
set :: p a c
-> DataDeclaration v a
-> p (EffectDeclaration v a) (DataDeclaration v a)
set p a c
decl DataDeclaration v a
dd = (a -> EffectDeclaration v a)
-> (c -> DataDeclaration v a)
-> p a c
-> p (EffectDeclaration v a) (DataDeclaration v a)
forall a b c d. (a -> b) -> (c -> d) -> p a c -> p b d
forall (p :: * -> * -> *) a b c d.
Bifunctor p =>
(a -> b) -> (c -> d) -> p a c -> p b d
bimap (DataDeclaration v a -> EffectDeclaration v a
forall v a. DataDeclaration v a -> EffectDeclaration v a
EffectDeclaration (DataDeclaration v a -> EffectDeclaration v a)
-> (a -> DataDeclaration v a) -> a -> EffectDeclaration v a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DataDeclaration v a -> a -> DataDeclaration v a
forall a b. a -> b -> a
const DataDeclaration v a
dd) (DataDeclaration v a -> c -> DataDeclaration v a
forall a b. a -> b -> a
const DataDeclaration v a
dd) p a c
decl
asDataDecl_ :: Iso' (EffectDeclaration v a) (DataDeclaration v a)
asDataDecl_ :: forall v a (p :: * -> * -> *) (f :: * -> *).
(Profunctor p, Functor f) =>
p (DataDeclaration v a) (f (DataDeclaration v a))
-> p (EffectDeclaration v a) (f (EffectDeclaration v a))
asDataDecl_ = (EffectDeclaration v a -> DataDeclaration v a)
-> (DataDeclaration v a -> EffectDeclaration v a)
-> Iso
(EffectDeclaration v a)
(EffectDeclaration v a)
(DataDeclaration v a)
(DataDeclaration v a)
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso EffectDeclaration v a -> DataDeclaration v a
forall v a. EffectDeclaration v a -> DataDeclaration v a
toDataDecl DataDeclaration v a -> EffectDeclaration v a
forall v a. DataDeclaration v a -> EffectDeclaration v a
EffectDeclaration
withEffectDeclM ::
(Functor f) =>
(DataDeclaration v a -> f (DataDeclaration v' a')) ->
EffectDeclaration v a ->
f (EffectDeclaration v' a')
withEffectDeclM :: forall (f :: * -> *) v a v' a'.
Functor f =>
(DataDeclaration v a -> f (DataDeclaration v' a'))
-> EffectDeclaration v a -> f (EffectDeclaration v' a')
withEffectDeclM DataDeclaration v a -> f (DataDeclaration v' a')
f = (DataDeclaration v' a' -> EffectDeclaration v' a')
-> f (DataDeclaration v' a') -> f (EffectDeclaration v' a')
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap DataDeclaration v' a' -> EffectDeclaration v' a'
forall v a. DataDeclaration v a -> EffectDeclaration v a
EffectDeclaration (f (DataDeclaration v' a') -> f (EffectDeclaration v' a'))
-> (EffectDeclaration v a -> f (DataDeclaration v' a'))
-> EffectDeclaration v a
-> f (EffectDeclaration v' a')
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DataDeclaration v a -> f (DataDeclaration v' a')
f (DataDeclaration v a -> f (DataDeclaration v' a'))
-> (EffectDeclaration v a -> DataDeclaration v a)
-> EffectDeclaration v a
-> f (DataDeclaration v' a')
forall b c a. (b -> c) -> (a -> b) -> a -> c
. EffectDeclaration v a -> DataDeclaration v a
forall v a. EffectDeclaration v a -> DataDeclaration v a
toDataDecl
constructorTypes :: DataDeclaration v a -> [Type v a]
constructorTypes :: forall v a. DataDeclaration v a -> [Type v a]
constructorTypes = ((v, Type v a) -> Type v a
forall a b. (a, b) -> b
snd ((v, Type v a) -> Type v a) -> [(v, Type v a)] -> [Type v a]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>) ([(v, Type v a)] -> [Type v a])
-> (DataDeclaration v a -> [(v, Type v a)])
-> DataDeclaration v a
-> [Type v a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DataDeclaration v a -> [(v, Type v a)]
forall v a. DataDeclaration v a -> [(v, Type v a)]
constructors
declFields :: (Var v) => Decl v a -> Either [Int] [Int]
declFields :: forall v a. Var v => Decl v a -> Either [Int] [Int]
declFields = (DataDeclaration v a -> [Int])
-> (DataDeclaration v a -> [Int])
-> Either (DataDeclaration v a) (DataDeclaration v a)
-> Either [Int] [Int]
forall a b c d. (a -> b) -> (c -> d) -> Either a c -> Either b d
forall (p :: * -> * -> *) a b c d.
Bifunctor p =>
(a -> b) -> (c -> d) -> p a c -> p b d
bimap DataDeclaration v a -> [Int]
forall {v} {a}. DataDeclaration v a -> [Int]
cf DataDeclaration v a -> [Int]
forall {v} {a}. DataDeclaration v a -> [Int]
cf (Either (DataDeclaration v a) (DataDeclaration v a)
-> Either [Int] [Int])
-> (Decl v a -> Either (DataDeclaration v a) (DataDeclaration v a))
-> Decl v a
-> Either [Int] [Int]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (EffectDeclaration v a -> DataDeclaration v a)
-> Decl v a -> Either (DataDeclaration v a) (DataDeclaration v a)
forall a b c. (a -> b) -> Either a c -> Either b c
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first EffectDeclaration v a -> DataDeclaration v a
forall v a. EffectDeclaration v a -> DataDeclaration v a
toDataDecl
where
cf :: DataDeclaration v a -> [Int]
cf = (Type v a -> Int) -> [Type v a] -> [Int]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Type v a -> Int
forall {v} {a}. Type v a -> Int
fields ([Type v a] -> [Int])
-> (DataDeclaration v a -> [Type v a])
-> DataDeclaration v a
-> [Int]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DataDeclaration v a -> [Type v a]
forall v a. DataDeclaration v a -> [Type v a]
constructorTypes
fields :: Type v a -> Int
fields (Type.ForallsNamed' [v]
_ Type v a
ty) = Type v a -> Int
fields Type v a
ty
fields (Type.Arrows' [Type v a]
spine) = [Type v a] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Type v a]
spine Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1
fields Type v a
_ = Int
0
typeOfConstructor :: DataDeclaration v a -> ConstructorId -> Maybe (Type v a)
typeOfConstructor :: forall v a.
DataDeclaration v a -> ConstructorId -> Maybe (Type v a)
typeOfConstructor DataDeclaration v a
dd ConstructorId
i = DataDeclaration v a -> [Type v a]
forall v a. DataDeclaration v a -> [Type v a]
constructorTypes DataDeclaration v a
dd [Type v a] -> Int -> Maybe (Type v a)
forall a. [a] -> Int -> Maybe a
`atMay` ConstructorId -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral ConstructorId
i
constructors :: DataDeclaration v a -> [(v, Type v a)]
constructors :: forall v a. DataDeclaration v a -> [(v, Type v a)]
constructors (DataDeclaration Modifier
_ a
_ [v]
_ [(a, v, Type v a)]
ctors) = [(v
v, Type v a
t) | (a
_, v
v, Type v a
t) <- [(a, v, Type v a)]
ctors]
constructorVars :: DataDeclaration v a -> [v]
constructorVars :: forall v a. DataDeclaration v a -> [v]
constructorVars DataDeclaration v a
dd = (v, Type v a) -> v
forall a b. (a, b) -> a
fst ((v, Type v a) -> v) -> [(v, Type v a)] -> [v]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> DataDeclaration v a -> [(v, Type v a)]
forall v a. DataDeclaration v a -> [(v, Type v a)]
constructors DataDeclaration v a
dd
constructorNames :: (Var v) => DataDeclaration v a -> [Text]
constructorNames :: forall v a. Var v => DataDeclaration v a -> [Text]
constructorNames DataDeclaration v a
dd = v -> Text
forall v. Var v => v -> Text
Var.name (v -> Text) -> [v] -> [Text]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> DataDeclaration v a -> [v]
forall v a. DataDeclaration v a -> [v]
constructorVars DataDeclaration v a
dd
setConstructorNames :: [v] -> Decl v a -> Decl v a
setConstructorNames :: forall v a. [v] -> Decl v a -> Decl v a
setConstructorNames [v]
constructorNames =
ASetter (Decl v a) (Decl v a) [(a, v, Type v a)] [(a, v, Type v a)]
-> ([(a, v, Type v a)] -> [(a, v, Type v a)])
-> Decl v a
-> Decl v a
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
over
((DataDeclaration v a -> Identity (DataDeclaration v a))
-> Decl v a -> Identity (Decl v a)
forall v a (f :: * -> *).
Functor f =>
(DataDeclaration v a -> f (DataDeclaration v a))
-> Decl v a -> f (Decl v a)
declAsDataDecl_ ((DataDeclaration v a -> Identity (DataDeclaration v a))
-> Decl v a -> Identity (Decl v a))
-> (([(a, v, Type v a)] -> Identity [(a, v, Type v a)])
-> DataDeclaration v a -> Identity (DataDeclaration v a))
-> ASetter
(Decl v a) (Decl v a) [(a, v, Type v a)] [(a, v, Type v a)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([(a, v, Type v a)] -> Identity [(a, v, Type v a)])
-> DataDeclaration v a -> Identity (DataDeclaration v a)
forall v a (f :: * -> *).
Functor f =>
([(a, v, Type v a)] -> f [(a, v, Type v a)])
-> DataDeclaration v a -> f (DataDeclaration v a)
constructors_)
((v -> (a, v, Type v a) -> (a, v, Type v a))
-> [v] -> [(a, v, Type v a)] -> [(a, v, Type v a)]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith (ASetter (a, v, Type v a) (a, v, Type v a) v v
-> v -> (a, v, Type v a) -> (a, v, Type v a)
forall s t a b. ASetter s t a b -> b -> s -> t
set ASetter (a, v, Type v a) (a, v, Type v a) v v
forall s t a b. Field2 s t a b => Lens s t a b
Lens (a, v, Type v a) (a, v, Type v a) v v
_2) [v]
constructorNames)
declConstructorReferents :: Reference.TypeReferenceId -> Decl v a -> [Referent.Id]
declConstructorReferents :: forall v a. Id' Hash -> Decl v a -> [Id]
declConstructorReferents Id' Hash
rid Decl v a
decl =
[GConstructorReference (Id' Hash) -> ConstructorType -> Id
forall r. GConstructorReference r -> ConstructorType -> Referent' r
Referent'.Con' (Id' Hash -> ConstructorId -> GConstructorReference (Id' Hash)
forall r. r -> ConstructorId -> GConstructorReference r
ConstructorReference Id' Hash
rid ConstructorId
i) ConstructorType
ct | ConstructorId
i <- DataDeclaration v a -> [ConstructorId]
forall v a. DataDeclaration v a -> [ConstructorId]
constructorIds (Decl v a -> DataDeclaration v a
forall v a. Decl v a -> DataDeclaration v a
asDataDecl Decl v a
decl)]
where
ct :: ConstructorType
ct = Decl v a -> ConstructorType
forall v a. Decl v a -> ConstructorType
constructorType Decl v a
decl
constructorIds :: DataDeclaration v a -> [ConstructorId]
constructorIds :: forall v a. DataDeclaration v a -> [ConstructorId]
constructorIds DataDeclaration v a
dd =
(Int -> Type v a -> ConstructorId) -> [Type v a] -> [ConstructorId]
forall a b. (Int -> a -> b) -> [a] -> [b]
forall i (f :: * -> *) a b.
FunctorWithIndex i f =>
(i -> a -> b) -> f a -> f b
imap (\Int
i Type v a
_ -> Int -> ConstructorId
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
i) (DataDeclaration v a -> [Type v a]
forall v a. DataDeclaration v a -> [Type v a]
constructorTypes DataDeclaration v a
dd)
allVars :: (Ord v) => DataDeclaration v a -> Set v
allVars :: forall v a. Ord v => DataDeclaration v a -> Set v
allVars (DataDeclaration Modifier
_ a
_ [v]
bound [(a, v, Type v a)]
ctors) =
[Set v] -> Set v
forall (f :: * -> *) a. (Foldable f, Ord a) => f (Set a) -> Set a
Set.unions ([Set v] -> Set v) -> [Set v] -> Set v
forall a b. (a -> b) -> a -> b
$
[v] -> Set v
forall a. Ord a => [a] -> Set a
Set.fromList [v]
bound Set v -> [Set v] -> [Set v]
forall a. a -> [a] -> [a]
: [v -> Set v -> Set v
forall a. Ord a => a -> Set a -> Set a
Set.insert v
v ([v] -> Set v
forall a. Ord a => [a] -> Set a
Set.fromList ([v] -> Set v) -> [v] -> Set v
forall a b. (a -> b) -> a -> b
$ Type v a -> [v]
forall (f :: * -> *) v a. Foldable f => Term f v a -> [v]
ABT.allVars Type v a
tp) | (a
_, v
v, Type v a
tp) <- [(a, v, Type v a)]
ctors]
allVars' :: (Ord v) => Decl v a -> Set v
allVars' :: forall v a. Ord v => Decl v a -> Set v
allVars' = DataDeclaration v a -> Set v
forall v a. Ord v => DataDeclaration v a -> Set v
allVars (DataDeclaration v a -> Set v)
-> (Decl v a -> DataDeclaration v a) -> Decl v a -> Set v
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (EffectDeclaration v a -> DataDeclaration v a)
-> (DataDeclaration v a -> DataDeclaration v a)
-> Decl v a
-> DataDeclaration v a
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either EffectDeclaration v a -> DataDeclaration v a
forall v a. EffectDeclaration v a -> DataDeclaration v a
toDataDecl DataDeclaration v a -> DataDeclaration v a
forall a. a -> a
id
bindReferences ::
(Var v) =>
(v -> Name.Name) ->
Set v ->
Map Name.Name Reference ->
DataDeclaration v a ->
Names.ResolutionResult a (DataDeclaration v a)
bindReferences :: forall v a.
Var v =>
(v -> Name)
-> Set v
-> Map Name Reference
-> DataDeclaration v a
-> ResolutionResult a (DataDeclaration v a)
bindReferences v -> Name
unsafeVarToName Set v
keepFree Map Name Reference
names (DataDeclaration Modifier
m a
a [v]
bound [(a, v, Type v a)]
constructors) = do
[(a, v, Type v a)]
constructors <- [(a, v, Type v a)]
-> ((a, v, Type v a)
-> Either (Seq (ResolutionFailure a)) (a, v, Type v a))
-> Either (Seq (ResolutionFailure a)) [(a, v, Type v a)]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
t a -> (a -> f b) -> f (t b)
for [(a, v, Type v a)]
constructors (((a, v, Type v a)
-> Either (Seq (ResolutionFailure a)) (a, v, Type v a))
-> Either (Seq (ResolutionFailure a)) [(a, v, Type v a)])
-> ((a, v, Type v a)
-> Either (Seq (ResolutionFailure a)) (a, v, Type v a))
-> Either (Seq (ResolutionFailure a)) [(a, v, Type v a)]
forall a b. (a -> b) -> a -> b
$ \(a
a, v
v, Type v a
ty) ->
(a
a,v
v,) (Type v a -> (a, v, Type v a))
-> Either (Seq (ResolutionFailure a)) (Type v a)
-> Either (Seq (ResolutionFailure a)) (a, v, Type v a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (v -> Name)
-> Set v
-> Map Name Reference
-> Type v a
-> Either (Seq (ResolutionFailure a)) (Type v a)
forall v a.
Var v =>
(v -> Name)
-> Set v
-> Map Name Reference
-> Type v a
-> ResolutionResult a (Type v a)
Type.bindReferences v -> Name
unsafeVarToName Set v
keepFree Map Name Reference
names Type v a
ty
DataDeclaration v a -> ResolutionResult a (DataDeclaration v a)
forall a. a -> Either (Seq (ResolutionFailure a)) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (DataDeclaration v a -> ResolutionResult a (DataDeclaration v a))
-> DataDeclaration v a -> ResolutionResult a (DataDeclaration v a)
forall a b. (a -> b) -> a -> b
$ Modifier -> a -> [v] -> [(a, v, Type v a)] -> DataDeclaration v a
forall v a.
Modifier -> a -> [v] -> [(a, v, Type v a)] -> DataDeclaration v a
DataDeclaration Modifier
m a
a [v]
bound [(a, v, Type v a)]
constructors
typeDependencies :: (Ord v) => DataDeclaration v a -> Set TypeReference
typeDependencies :: forall v a. Ord v => DataDeclaration v a -> Set Reference
typeDependencies DataDeclaration v a
dd =
[Set Reference] -> Set Reference
forall (f :: * -> *) a. (Foldable f, Ord a) => f (Set a) -> Set a
Set.unions (Type v a -> Set Reference
forall v a. Ord v => Type v a -> Set Reference
Type.dependencies (Type v a -> Set Reference) -> [Type v a] -> [Set Reference]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> DataDeclaration v a -> [Type v a]
forall v a. DataDeclaration v a -> [Type v a]
constructorTypes DataDeclaration v a
dd)
labeledTypeDependencies :: (Ord v) => DataDeclaration v a -> Set LD.LabeledDependency
labeledTypeDependencies :: forall v a. Ord v => DataDeclaration v a -> Set LabeledDependency
labeledTypeDependencies = (Reference -> LabeledDependency)
-> Set Reference -> Set LabeledDependency
forall b a. Ord b => (a -> b) -> Set a -> Set b
Set.map Reference -> LabeledDependency
LD.TypeReference (Set Reference -> Set LabeledDependency)
-> (DataDeclaration v a -> Set Reference)
-> DataDeclaration v a
-> Set LabeledDependency
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DataDeclaration v a -> Set Reference
forall v a. Ord v => DataDeclaration v a -> Set Reference
typeDependencies
mkEffectDecl' ::
Modifier -> a -> [v] -> [(a, v, Type v a)] -> EffectDeclaration v a
mkEffectDecl' :: forall a v.
Modifier -> a -> [v] -> [(a, v, Type v a)] -> EffectDeclaration v a
mkEffectDecl' Modifier
m a
a [v]
b [(a, v, Type v a)]
cs = DataDeclaration v a -> EffectDeclaration v a
forall v a. DataDeclaration v a -> EffectDeclaration v a
EffectDeclaration (Modifier -> a -> [v] -> [(a, v, Type v a)] -> DataDeclaration v a
forall v a.
Modifier -> a -> [v] -> [(a, v, Type v a)] -> DataDeclaration v a
DataDeclaration Modifier
m a
a [v]
b [(a, v, Type v a)]
cs)
mkDataDecl' ::
Modifier -> a -> [v] -> [(a, v, Type v a)] -> DataDeclaration v a
mkDataDecl' :: forall a v.
Modifier -> a -> [v] -> [(a, v, Type v a)] -> DataDeclaration v a
mkDataDecl' = Modifier -> a -> [v] -> [(a, v, Type v a)] -> DataDeclaration v a
forall v a.
Modifier -> a -> [v] -> [(a, v, Type v a)] -> DataDeclaration v a
DataDeclaration
data F a
= Type (Type.F a)
| LetRec [a] a
| Constructors [a]
| Modified Modifier a
deriving ((forall a b. (a -> b) -> F a -> F b)
-> (forall a b. a -> F b -> F a) -> Functor F
forall a b. a -> F b -> F a
forall a b. (a -> b) -> F a -> F b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall a b. (a -> b) -> F a -> F b
fmap :: forall a b. (a -> b) -> F a -> F b
$c<$ :: forall a b. a -> F b -> F a
<$ :: forall a b. a -> F b -> F a
Functor, (forall m. Monoid m => F m -> m)
-> (forall m a. Monoid m => (a -> m) -> F a -> m)
-> (forall m a. Monoid m => (a -> m) -> F a -> m)
-> (forall a b. (a -> b -> b) -> b -> F a -> b)
-> (forall a b. (a -> b -> b) -> b -> F a -> b)
-> (forall b a. (b -> a -> b) -> b -> F a -> b)
-> (forall b a. (b -> a -> b) -> b -> F a -> b)
-> (forall a. (a -> a -> a) -> F a -> a)
-> (forall a. (a -> a -> a) -> F a -> a)
-> (forall a. F a -> [a])
-> (forall a. F a -> Bool)
-> (forall a. F a -> Int)
-> (forall a. Eq a => a -> F a -> Bool)
-> (forall a. Ord a => F a -> a)
-> (forall a. Ord a => F a -> a)
-> (forall a. Num a => F a -> a)
-> (forall a. Num a => F a -> a)
-> Foldable F
forall a. Eq a => a -> F a -> Bool
forall a. Num a => F a -> a
forall a. Ord a => F a -> a
forall m. Monoid m => F m -> m
forall a. F a -> Bool
forall a. F a -> Int
forall a. F a -> [a]
forall a. (a -> a -> a) -> F a -> a
forall m a. Monoid m => (a -> m) -> F a -> m
forall b a. (b -> a -> b) -> b -> F a -> b
forall a b. (a -> b -> b) -> b -> F a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
$cfold :: forall m. Monoid m => F m -> m
fold :: forall m. Monoid m => F m -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> F a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> F a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> F a -> m
foldMap' :: forall m a. Monoid m => (a -> m) -> F a -> m
$cfoldr :: forall a b. (a -> b -> b) -> b -> F a -> b
foldr :: forall a b. (a -> b -> b) -> b -> F a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> F a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> F a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> F a -> b
foldl :: forall b a. (b -> a -> b) -> b -> F a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> F a -> b
foldl' :: forall b a. (b -> a -> b) -> b -> F a -> b
$cfoldr1 :: forall a. (a -> a -> a) -> F a -> a
foldr1 :: forall a. (a -> a -> a) -> F a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> F a -> a
foldl1 :: forall a. (a -> a -> a) -> F a -> a
$ctoList :: forall a. F a -> [a]
toList :: forall a. F a -> [a]
$cnull :: forall a. F a -> Bool
null :: forall a. F a -> Bool
$clength :: forall a. F a -> Int
length :: forall a. F a -> Int
$celem :: forall a. Eq a => a -> F a -> Bool
elem :: forall a. Eq a => a -> F a -> Bool
$cmaximum :: forall a. Ord a => F a -> a
maximum :: forall a. Ord a => F a -> a
$cminimum :: forall a. Ord a => F a -> a
minimum :: forall a. Ord a => F a -> a
$csum :: forall a. Num a => F a -> a
sum :: forall a. Num a => F a -> a
$cproduct :: forall a. Num a => F a -> a
product :: forall a. Num a => F a -> a
Foldable, Int -> F a -> ShowS
[F a] -> ShowS
F a -> String
(Int -> F a -> ShowS)
-> (F a -> String) -> ([F a] -> ShowS) -> Show (F a)
forall a. Show a => Int -> F a -> ShowS
forall a. Show a => [F a] -> ShowS
forall a. Show a => F a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Show a => Int -> F a -> ShowS
showsPrec :: Int -> F a -> ShowS
$cshow :: forall a. Show a => F a -> String
show :: F a -> String
$cshowList :: forall a. Show a => [F a] -> ShowS
showList :: [F a] -> ShowS
Show)
updateDependencies :: (Ord v) => Map Reference Reference -> Decl v a -> Decl v a
updateDependencies :: forall v a.
Ord v =>
Map Reference Reference -> Decl v a -> Decl v a
updateDependencies Map Reference Reference
typeUpdates Decl v a
decl =
DataDeclaration v a -> Decl v a
back (DataDeclaration v a -> Decl v a)
-> DataDeclaration v a -> Decl v a
forall a b. (a -> b) -> a -> b
$
DataDeclaration v a
dataDecl
{ constructors' =
over _3 (Type.updateDependencies typeUpdates)
<$> constructors' dataDecl
}
where
dataDecl :: DataDeclaration v a
dataDecl = (EffectDeclaration v a -> DataDeclaration v a)
-> (DataDeclaration v a -> DataDeclaration v a)
-> Decl v a
-> DataDeclaration v a
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either EffectDeclaration v a -> DataDeclaration v a
forall v a. EffectDeclaration v a -> DataDeclaration v a
toDataDecl DataDeclaration v a -> DataDeclaration v a
forall a. a -> a
id Decl v a
decl
back :: DataDeclaration v a -> Decl v a
back = (EffectDeclaration v a -> DataDeclaration v a -> Decl v a)
-> (DataDeclaration v a -> DataDeclaration v a -> Decl v a)
-> Decl v a
-> DataDeclaration v a
-> Decl v a
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either ((DataDeclaration v a -> Decl v a)
-> EffectDeclaration v a -> DataDeclaration v a -> Decl v a
forall a b. a -> b -> a
const ((DataDeclaration v a -> Decl v a)
-> EffectDeclaration v a -> DataDeclaration v a -> Decl v a)
-> (DataDeclaration v a -> Decl v a)
-> EffectDeclaration v a
-> DataDeclaration v a
-> Decl v a
forall a b. (a -> b) -> a -> b
$ EffectDeclaration v a -> Decl v a
forall a b. a -> Either a b
Left (EffectDeclaration v a -> Decl v a)
-> (DataDeclaration v a -> EffectDeclaration v a)
-> DataDeclaration v a
-> Decl v a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DataDeclaration v a -> EffectDeclaration v a
forall v a. DataDeclaration v a -> EffectDeclaration v a
EffectDeclaration) ((DataDeclaration v a -> Decl v a)
-> DataDeclaration v a -> DataDeclaration v a -> Decl v a
forall a b. a -> b -> a
const DataDeclaration v a -> Decl v a
forall a b. b -> Either a b
Right) Decl v a
decl
unhashComponent ::
forall v a. (Var v) => Map Reference.Id (Decl v a) -> Map Reference.Id (v, Decl v a)
unhashComponent :: forall v a.
Var v =>
Map (Id' Hash) (Decl v a) -> Map (Id' Hash) (v, Decl v a)
unhashComponent Map (Id' Hash) (Decl v a)
m =
let usedVars :: Set v
usedVars :: Set v
usedVars = (Decl v a -> Set v) -> Map (Id' Hash) (Decl v a) -> Set v
forall m a. Monoid m => (a -> m) -> Map (Id' Hash) a -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap Decl v a -> Set v
forall v a. Ord v => Decl v a -> Set v
allVars' Map (Id' Hash) (Decl v a)
m
m' :: Map Reference.Id (v, Decl v a)
m' :: Map (Id' Hash) (v, Decl v a)
m' = State (Set v) (Map (Id' Hash) (v, Decl v a))
-> Set v -> Map (Id' Hash) (v, Decl v a)
forall s a. State s a -> s -> a
evalState ((Id' Hash -> Decl v a -> StateT (Set v) Identity (v, Decl v a))
-> Map (Id' Hash) (Decl v a)
-> State (Set v) (Map (Id' Hash) (v, Decl v a))
forall (t :: * -> *) k a b.
Applicative t =>
(k -> a -> t b) -> Map k a -> t (Map k b)
Map.traverseWithKey Id' Hash -> Decl v a -> StateT (Set v) Identity (v, Decl v a)
forall {f :: * -> *} {a} {t}.
(MonadState (Set a) f, Var a) =>
Id' Hash -> t -> f (a, t)
assignVar Map (Id' Hash) (Decl v a)
m) Set v
usedVars
where
assignVar :: Id' Hash -> t -> f (a, t)
assignVar Id' Hash
r t
d = (,t
d) (a -> (a, t)) -> f a -> f (a, t)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f a
forall v (m :: * -> *). (Var v, MonadState (Set v) m) => v -> m v
ABT.freshenS (Id' Hash -> a
forall v. Var v => Id' Hash -> v
Var.unnamedRef Id' Hash
r)
unhash1 :: ABT.Term Type.F v a -> ABT.Term Type.F v a
unhash1 :: Type v a -> Type v a
unhash1 = (Type v a -> Type v a) -> Type v a -> Type v a
forall v (f :: * -> *) a.
(Ord v, Foldable f, Functor f) =>
(Term f v a -> Term f v a) -> Term f v a -> Term f v a
ABT.rebuildUp' Type v a -> Type v a
go
where
go :: Type v a -> Type v a
go e :: Type v a
e@(Type.Ref' (Reference.DerivedId Id' Hash
r)) = case Id' Hash -> Map (Id' Hash) (v, Decl v a) -> Maybe (v, Decl v a)
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup Id' Hash
r Map (Id' Hash) (v, Decl v a)
m' of
Maybe (v, Decl v a)
Nothing -> Type v a
e
Just (v
v, Decl v a
_) -> a -> v -> Type v a
forall v a. Ord v => a -> v -> Type v a
Type.var (Type v a -> a
forall (f :: * -> *) v a. Term f v a -> a
ABT.annotation Type v a
e) v
v
go Type v a
e = Type v a
e
unhash2 :: Decl v a -> Decl v a
unhash2 (Right dd :: DataDeclaration v a
dd@DataDeclaration {}) = DataDeclaration v a -> Decl v a
forall a b. b -> Either a b
Right (DataDeclaration v a -> Decl v a)
-> DataDeclaration v a -> Decl v a
forall a b. (a -> b) -> a -> b
$ DataDeclaration v a -> DataDeclaration v a
unhash3 DataDeclaration v a
dd
unhash2 (Left (EffectDeclaration DataDeclaration v a
dd)) =
EffectDeclaration v a -> Decl v a
forall a b. a -> Either a b
Left (EffectDeclaration v a -> Decl v a)
-> (DataDeclaration v a -> EffectDeclaration v a)
-> DataDeclaration v a
-> Decl v a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DataDeclaration v a -> EffectDeclaration v a
forall v a. DataDeclaration v a -> EffectDeclaration v a
EffectDeclaration (DataDeclaration v a -> Decl v a)
-> DataDeclaration v a -> Decl v a
forall a b. (a -> b) -> a -> b
$ DataDeclaration v a -> DataDeclaration v a
unhash3 DataDeclaration v a
dd
unhash3 :: DataDeclaration v a -> DataDeclaration v a
unhash3 dd :: DataDeclaration v a
dd@DataDeclaration {a
[v]
[(a, v, Type v a)]
Modifier
$sel:modifier:DataDeclaration :: forall v a. DataDeclaration v a -> Modifier
$sel:annotation:DataDeclaration :: forall v a. DataDeclaration v a -> a
$sel:bound:DataDeclaration :: forall v a. DataDeclaration v a -> [v]
$sel:constructors':DataDeclaration :: forall v a. DataDeclaration v a -> [(a, v, Type v a)]
modifier :: Modifier
annotation :: a
bound :: [v]
constructors' :: [(a, v, Type v a)]
..} =
DataDeclaration v a
dd {constructors' = fmap (over _3 unhash1) constructors'}
in (Decl v a -> Decl v a) -> (v, Decl v a) -> (v, Decl v a)
forall b c a. (b -> c) -> (a, b) -> (a, c)
forall (p :: * -> * -> *) b c a.
Bifunctor p =>
(b -> c) -> p a b -> p a c
second Decl v a -> Decl v a
unhash2 ((v, Decl v a) -> (v, Decl v a))
-> Map (Id' Hash) (v, Decl v a) -> Map (Id' Hash) (v, Decl v a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Map (Id' Hash) (v, Decl v a)
m'
amap :: (a -> a2) -> Decl v a -> Decl v a2
amap :: forall a a2 v. (a -> a2) -> Decl v a -> Decl v a2
amap a -> a2
f (Left EffectDeclaration v a
e) = EffectDeclaration v a2
-> Either (EffectDeclaration v a2) (DataDeclaration v a2)
forall a b. a -> Either a b
Left (a -> a2
f (a -> a2) -> EffectDeclaration v a -> EffectDeclaration v a2
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> EffectDeclaration v a
e)
amap a -> a2
f (Right DataDeclaration v a
d) = DataDeclaration v a2
-> Either (EffectDeclaration v a2) (DataDeclaration v a2)
forall a b. b -> Either a b
Right (a -> a2
f (a -> a2) -> DataDeclaration v a -> DataDeclaration v a2
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> DataDeclaration v a
d)