-
Notifications
You must be signed in to change notification settings - Fork 481
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Builtins] Disentangle 'KnownTypeAst' from 'KnownTypeIn' #4312
Changes from all commits
c1beb8a
20fd9d8
4693b29
c42a9f2
00740cd
8fcee47
7d3c855
d0f9195
4ba7a72
f7bd7dd
0b360ad
f10c848
f6426c1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,6 +102,8 @@ data ExtensionFun | |
| ExpensiveSucc | ||
| FailingPlus | ||
| ExpensivePlus | ||
| UnsafeCoerce | ||
| UnsafeCoerceEl | ||
| Undefined | ||
| Absurd | ||
| ErrorPrime -- Like 'Error', but a builtin. What do we even need 'Error' for at this point? | ||
|
@@ -132,6 +134,7 @@ defBuiltinsRuntimeExt = toBuiltinsRuntime (defaultBuiltinCostModel, ()) | |
|
||
data PlcListRep (a :: GHC.Type) | ||
instance KnownTypeAst uni a => KnownTypeAst uni (PlcListRep a) where | ||
type ToHoles (PlcListRep a) = '[RepHole a] | ||
type ToBinds (PlcListRep a) = ToBinds a | ||
|
||
toTypeAst _ = TyApp () Plc.listTy . toTypeAst $ Proxy @a | ||
|
@@ -179,25 +182,18 @@ instance uni ~ DefaultUni => ToBuiltinMeaning uni ExtensionFun where | |
|
||
toBuiltinMeaning IdFInteger = | ||
makeBuiltinMeaning | ||
(Prelude.id | ||
:: a ~ Opaque term (TyAppRep (TyVarRep ('TyNameRep "f" 0)) Integer) | ||
=> a -> a) | ||
(Prelude.id :: fi ~ Opaque term (TyAppRep f Integer) => fi -> fi) | ||
(\_ _ -> ExBudget 1 0) | ||
|
||
toBuiltinMeaning IdList = | ||
makeBuiltinMeaning | ||
(Prelude.id | ||
:: a ~ Opaque term (PlcListRep (TyVarRep ('TyNameRep "a" 0))) | ||
=> a -> a) | ||
(Prelude.id :: la ~ Opaque term (PlcListRep a) => la -> la) | ||
Comment on lines
-189
to
+190
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and basically any |
||
(\_ _ -> ExBudget 1 0) | ||
|
||
toBuiltinMeaning IdRank2 = | ||
makeBuiltinMeaning | ||
(Prelude.id | ||
:: ( f ~ 'TyNameRep "f" 0 | ||
, a ~ 'TyNameRep @GHC.Type "a" 1 | ||
, afa ~ Opaque term (TyForallRep a (TyAppRep (TyVarRep f) (TyVarRep a))) | ||
) | ||
:: afa ~ Opaque term (TyForallRep a (TyAppRep (TyVarRep f) (TyVarRep a))) | ||
Comment on lines
-197
to
+196
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. other |
||
=> afa -> afa) | ||
(\_ _ -> ExBudget 1 0) | ||
|
||
|
@@ -225,6 +221,23 @@ instance uni ~ DefaultUni => ToBuiltinMeaning uni ExtensionFun where | |
(\_ _ -> throw BuiltinErrorCall) | ||
(\_ _ _ -> unExRestrictingBudget enormousBudget) | ||
|
||
toBuiltinMeaning UnsafeCoerce = | ||
makeBuiltinMeaning | ||
(Opaque . unOpaque) | ||
(\_ _ -> ExBudget 1 0) | ||
|
||
toBuiltinMeaning UnsafeCoerceEl = | ||
makeBuiltinMeaning | ||
unsafeCoerceElPlc | ||
(\_ _ -> ExBudget 1 0) | ||
where | ||
unsafeCoerceElPlc | ||
:: SomeConstant DefaultUni [a] | ||
-> EvaluationResult (SomeConstant DefaultUni [b]) | ||
unsafeCoerceElPlc (SomeConstant (Some (ValueOf uniList xs))) = do | ||
DefaultUniList _ <- pure uniList | ||
pure . SomeConstant $ someValueOf uniList xs | ||
|
||
toBuiltinMeaning Undefined = | ||
makeBuiltinMeaning | ||
undefined | ||
|
@@ -244,40 +257,39 @@ instance uni ~ DefaultUni => ToBuiltinMeaning uni ExtensionFun where | |
commaPlc | ||
:: SomeConstant uni a | ||
-> SomeConstant uni b | ||
-> SomeConstantPoly uni (,) '[a, b] | ||
-> SomeConstant uni (a, b) | ||
Comment on lines
-247
to
+260
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Quite nicer, isn't it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The rest of the file does look quite a bit more readable. |
||
commaPlc (SomeConstant (Some (ValueOf uniA x))) (SomeConstant (Some (ValueOf uniB y))) = | ||
SomeConstantPoly $ someValueOf (DefaultUniPair uniA uniB) (x, y) | ||
SomeConstant $ someValueOf (DefaultUniPair uniA uniB) (x, y) | ||
|
||
toBuiltinMeaning BiconstPair = makeBuiltinMeaning biconstPairPlc mempty where | ||
biconstPairPlc | ||
:: SomeConstant uni a | ||
-> SomeConstant uni b | ||
-> SomeConstantPoly uni (,) '[a, b] | ||
-> EvaluationResult (SomeConstantPoly uni (,) '[a, b]) | ||
-> SomeConstant uni (a, b) | ||
-> EvaluationResult (SomeConstant uni (a, b)) | ||
biconstPairPlc | ||
(SomeConstant (Some (ValueOf uniA x))) | ||
(SomeConstant (Some (ValueOf uniB y))) | ||
(SomeConstantPoly (Some (ValueOf uniPairAB _))) = do | ||
(SomeConstant (Some (ValueOf uniPairAB _))) = do | ||
DefaultUniPair uniA' uniB' <- pure uniPairAB | ||
Just Refl <- pure $ uniA `geq` uniA' | ||
Just Refl <- pure $ uniB `geq` uniB' | ||
pure . SomeConstantPoly $ someValueOf uniPairAB (x, y) | ||
pure . SomeConstant $ someValueOf uniPairAB (x, y) | ||
|
||
toBuiltinMeaning Swap = makeBuiltinMeaning swapPlc mempty where | ||
swapPlc | ||
:: SomeConstantPoly uni (,) '[a, b] | ||
-> EvaluationResult (SomeConstantPoly uni (,) '[b, a]) | ||
swapPlc (SomeConstantPoly (Some (ValueOf uniPairAB p))) = do | ||
:: SomeConstant uni (a, b) | ||
-> EvaluationResult (SomeConstant uni (b, a)) | ||
swapPlc (SomeConstant (Some (ValueOf uniPairAB p))) = do | ||
DefaultUniPair uniA uniB <- pure uniPairAB | ||
pure . SomeConstantPoly $ someValueOf (DefaultUniPair uniB uniA) (snd p, fst p) | ||
pure . SomeConstant $ someValueOf (DefaultUniPair uniB uniA) (snd p, fst p) | ||
|
||
toBuiltinMeaning SwapEls = makeBuiltinMeaning swapElsPlc mempty where | ||
-- The type reads as @[(a, Bool)] -> [(Bool, a)]@. | ||
swapElsPlc | ||
:: a ~ Opaque term (TyVarRep ('TyNameRep "a" 0)) | ||
=> SomeConstantPoly uni [] '[SomeConstantPoly uni (,) '[a, Bool]] | ||
-> EvaluationResult (SomeConstantPoly uni [] '[SomeConstantPoly uni (,) '[Bool, a]]) | ||
swapElsPlc (SomeConstantPoly (Some (ValueOf uniList xs))) = do | ||
:: SomeConstant uni [SomeConstant uni (a, Bool)] | ||
-> EvaluationResult (SomeConstant uni [SomeConstant uni (Bool, a)]) | ||
swapElsPlc (SomeConstant (Some (ValueOf uniList xs))) = do | ||
DefaultUniList (DefaultUniPair uniA DefaultUniBool) <- pure uniList | ||
let uniList' = DefaultUniList $ DefaultUniPair DefaultUniBool uniA | ||
pure . SomeConstantPoly . someValueOf uniList' $ map swap xs | ||
pure . SomeConstant . someValueOf uniList' $ map swap xs |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,32 +22,31 @@ type TermDebug = Term TyName Name DefaultUni DefaultFun () | |
-- | ||
-- >>> :t enumerateDebug False | ||
-- enumerateDebug False :: Bool | ||
-- >>> :t enumerateDebug $ Just 'a' | ||
-- enumerateDebug $ Just 'a' :: Maybe Char | ||
Comment on lines
-25
to
-26
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Had to drop it, 'cause it now generates a ton of garbage instead of being stuck. I'll work on it some time later. |
||
-- >>> :t enumerateDebug $ \_ -> () | ||
-- enumerateDebug $ \_ -> () | ||
-- :: Opaque | ||
-- (Term TyName Name DefaultUni DefaultFun ()) | ||
-- (TyVarRep ('TyNameRep "a" 0)) | ||
-- -> () | ||
-- >>> :t enumerateDebug 42 | ||
-- <interactive>:1:16-17: error: | ||
-- <interactive>:1:16: error: | ||
-- • Built-in functions are not allowed to have constraints | ||
-- To fix this error instantiate all constrained type variables | ||
-- • In the first argument of ‘enumerateDebug’, namely ‘42’ | ||
-- In the expression: enumerateDebug 42 | ||
enumerateDebug :: forall a j. EnumerateFromTo 0 j TermDebug a => a -> a | ||
enumerateDebug = id | ||
specializeDebug :: forall a j. SpecializeFromTo 0 j TermDebug a => a -> a | ||
specializeDebug = id | ||
|
||
-- | Instantiate type variables in the type of a value using 'EnumerateFromTo' and check that it's | ||
-- possible to construct a 'TypeScheme' out of the resulting type. Example usages: | ||
-- | ||
-- >>> :t inferDebug False | ||
-- inferDebug False :: Bool | ||
-- >>> :t inferDebug $ Just 'a' | ||
-- <interactive>:1:1-21: error: | ||
-- • There's no 'KnownType' instance for Maybe Char | ||
-- Did you add a new built-in type and forget to provide a 'KnownType' instance for it? | ||
-- <interactive>:1:1: error: | ||
-- • No instance for (KnownPolytype | ||
-- (ToBinds (Maybe Char)) TermDebug '[] (Maybe Char) (Maybe Char)) | ||
-- arising from a use of ‘inferDebug’ | ||
Comment on lines
-48
to
+49
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I dropped that custom type error some time ago, 'cause it was playing badly with some other parts of the code. I'll try to reintroduce it later. |
||
-- • In the expression: inferDebug $ Just 'a' | ||
-- >>> :t inferDebug $ \_ -> () | ||
-- inferDebug $ \_ -> () | ||
|
@@ -58,8 +57,7 @@ enumerateDebug = id | |
inferDebug | ||
:: forall a binds args res j. | ||
( args ~ GetArgs a, a ~ FoldArgs args res, binds ~ Merge (ListToBinds args) (ToBinds res) | ||
, KnownPolytype binds TermDebug args res a, EnumerateFromTo 0 j TermDebug a | ||
, KnownMonotype TermDebug args res a | ||
, KnownPolytype binds TermDebug args res a, SpecializeFromTo 0 j TermDebug a | ||
) | ||
=> a -> a | ||
inferDebug = id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The inference machinery now is able to look under
TyAppRep