@@ -68,11 +68,31 @@ data AppBuilder = AppBuilder
68
68
_appBuilderArgs :: [AppBuilderArg ]
69
69
}
70
70
71
+ data TypeHint = TypeHint
72
+ { _typeHint :: Maybe Expression ,
73
+ _typeHintTypeNatural :: Bool
74
+ }
75
+
76
+ makeLenses ''TypeHint
71
77
makeLenses ''AppBuilder
72
78
makeLenses ''AppBuilderArg
73
79
makeLenses ''FunctionDefault
74
80
makeLenses ''FunctionDefaultInfo
75
81
82
+ mkTypeHint :: Maybe Expression -> TypeHint
83
+ mkTypeHint ty =
84
+ TypeHint
85
+ { _typeHint = ty,
86
+ _typeHintTypeNatural = False
87
+ }
88
+
89
+ emptyTypeHint :: TypeHint
90
+ emptyTypeHint =
91
+ TypeHint
92
+ { _typeHint = Nothing ,
93
+ _typeHintTypeNatural = False
94
+ }
95
+
76
96
instance PrettyCode FunctionDefault where
77
97
ppCode _ = return " ppCode(FunctionDefault)"
78
98
@@ -332,9 +352,9 @@ checkMutualStatement ::
332
352
Sem r MutualStatement
333
353
checkMutualStatement = \ case
334
354
StatementFunction f -> do
335
- traceM (" f : " <> ppTrace f)
355
+ -- traceM ("f : " <> ppTrace f)
336
356
f' <- resolveInstanceHoles (resolveCastHoles (checkFunctionDef f))
337
- traceM (" f' : " <> ppTrace f')
357
+ -- traceM ("f' : " <> ppTrace f')
338
358
return (StatementFunction f')
339
359
StatementInductive f -> StatementInductive <$> resolveInstanceHoles (resolveCastHoles (checkInductiveDef f))
340
360
StatementAxiom ax -> do
@@ -363,7 +383,7 @@ checkFunctionDef ::
363
383
checkFunctionDef FunctionDef {.. } = do
364
384
funDef <- do
365
385
_funDefType' <- checkDefType _funDefType
366
- traceM (" ----------------fundeftype': " <> ppTrace _funDefType')
386
+ -- traceM ("----------------fundeftype': " <> ppTrace _funDefType')
367
387
registerIdenType _funDefName _funDefType'
368
388
_funDefBody' <- checkFunctionBody _funDefType' _funDefBody
369
389
params <- fst <$> unfoldFunType' _funDefType'
@@ -580,7 +600,11 @@ checkExpression ::
580
600
Expression ->
581
601
Sem r Expression
582
602
checkExpression expectedTy e = do
583
- e' <- inferExpression' (Just expectedTy) e
603
+ let hint = TypeHint {
604
+ _typeHint = Just expectedTy,
605
+ _typeHintTypeNatural = False
606
+ }
607
+ e' <- inferExpression' hint e
584
608
let inferredType = e' ^. typedType
585
609
whenJustM (matchTypes expectedTy inferredType) (const (err e'))
586
610
return (e' ^. typedExpression)
@@ -649,7 +673,7 @@ inferExpressionRepl ::
649
673
Maybe Expression ->
650
674
Expression ->
651
675
Sem r TypedExpression
652
- inferExpressionRepl hint = resolveInstanceHoles . resolveCastHoles . inferExpression' hint
676
+ inferExpressionRepl hint = resolveInstanceHoles . resolveCastHoles . inferExpression' (mkTypeHint hint)
653
677
654
678
lookupVar ::
655
679
(HasCallStack ) =>
@@ -979,7 +1003,7 @@ checkPattern = go
979
1003
inferExpression' ::
980
1004
forall r .
981
1005
(Members '[Reader InfoTable , Reader BuiltinsTable , ResultBuilder , Reader LocalVars , Error TypeCheckerError , NameIdGen , Inference , Output TypedInstanceHole , Termination , Output CastHole , Reader InsertedArgsStack , Reader InsertedArgsStack ] r ) =>
982
- Maybe Expression ->
1006
+ TypeHint ->
983
1007
Expression ->
984
1008
Sem r TypedExpression
985
1009
inferExpression' = holesHelper
@@ -988,7 +1012,7 @@ inferExpression' = holesHelper
988
1012
inferLeftAppExpression ::
989
1013
forall r .
990
1014
(Members '[Reader InfoTable , Reader BuiltinsTable , ResultBuilder , Reader LocalVars , Error TypeCheckerError , NameIdGen , Inference , Output TypedInstanceHole , Termination , Output CastHole , Reader InsertedArgsStack ] r ) =>
991
- Maybe Expression ->
1015
+ TypeHint ->
992
1016
Expression ->
993
1017
Sem r TypedExpression
994
1018
inferLeftAppExpression mhint e = case e of
@@ -1030,7 +1054,7 @@ inferLeftAppExpression mhint e = case e of
1030
1054
goHole :: Hole -> Sem r TypedExpression
1031
1055
goHole h = do
1032
1056
void (queryMetavar h)
1033
- ty <- maybe (freshHoleImpl (getLoc h) Implicit ) return mhint
1057
+ ty <- maybe (freshHoleImpl (getLoc h) Implicit ) return ( mhint ^. typeHint)
1034
1058
return
1035
1059
TypedExpression
1036
1060
{ _typedExpression = ExpressionHole h,
@@ -1039,7 +1063,7 @@ inferLeftAppExpression mhint e = case e of
1039
1063
1040
1064
goInstanceHole :: InstanceHole -> Sem r TypedExpression
1041
1065
goInstanceHole h = do
1042
- let ty = fromMaybe impossible mhint
1066
+ let ty = fromMaybe impossible ( mhint ^. typeHint)
1043
1067
locals <- ask
1044
1068
output (TypedInstanceHole h ty locals)
1045
1069
return
@@ -1050,7 +1074,7 @@ inferLeftAppExpression mhint e = case e of
1050
1074
1051
1075
goSimpleLambda :: SimpleLambda -> Sem r TypedExpression
1052
1076
goSimpleLambda (SimpleLambda (SimpleBinder v ty) b) = do
1053
- b' <- withLocalType v ty (inferExpression' Nothing b)
1077
+ b' <- withLocalType v ty (inferExpression' emptyTypeHint b)
1054
1078
let smallUni = smallUniverseE (getLoc ty)
1055
1079
ty' <- checkExpression smallUni ty
1056
1080
let fun = Function (unnamedParameter smallUni) (b' ^. typedType)
@@ -1062,10 +1086,10 @@ inferLeftAppExpression mhint e = case e of
1062
1086
1063
1087
goCase :: Case -> Sem r TypedExpression
1064
1088
goCase c = do
1065
- ty <- case mhint of
1089
+ ty <- case mhint ^. typeHint of
1066
1090
Nothing -> freshHoleImpl (getLoc c) Implicit
1067
1091
Just hi -> return hi
1068
- typedCaseExpression <- inferExpression' Nothing (c ^. caseExpression)
1092
+ typedCaseExpression <- inferExpression' emptyTypeHint (c ^. caseExpression)
1069
1093
let _caseExpression = typedCaseExpression ^. typedExpression
1070
1094
_caseExpressionType = Just (typedCaseExpression ^. typedType)
1071
1095
_caseExpressionWholeType = Just ty
@@ -1093,7 +1117,7 @@ inferLeftAppExpression mhint e = case e of
1093
1117
1094
1118
goLambda :: Lambda -> Sem r TypedExpression
1095
1119
goLambda l = do
1096
- ty <- case mhint of
1120
+ ty <- case mhint ^. typeHint of
1097
1121
Just hi -> return hi
1098
1122
Nothing -> freshHoleImpl (getLoc l) Implicit
1099
1123
_lambdaClauses <- mapM (goClause ty) (l ^. lambdaClauses)
@@ -1169,8 +1193,9 @@ inferLeftAppExpression mhint e = case e of
1169
1193
typedLit litt blt ty = do
1170
1194
from <- getBuiltinNameTypeChecker i blt
1171
1195
ihole <- freshHoleImpl i ImplicitInstance
1172
- let ty' = maybe ty (adjustLocation i) mhint
1173
- inferExpression' (Just ty') $
1196
+ let ty' = maybe ty (adjustLocation i) (mhint ^. typeHint)
1197
+ -- inferExpression' (Just ty') $
1198
+ inferExpression' todo $
1174
1199
foldApplication
1175
1200
(ExpressionIden (IdenFunction from))
1176
1201
[ ApplicationArg Implicit ty',
@@ -1218,13 +1243,13 @@ inferLeftAppExpression mhint e = case e of
1218
1243
kind <- lookupInductiveType v
1219
1244
return (TypedExpression kind (ExpressionIden i))
1220
1245
1221
- -- | The hint is used for trailing holes only
1222
- holesHelper :: forall r . (Members '[Reader InfoTable , Reader BuiltinsTable , ResultBuilder , Reader LocalVars , Error TypeCheckerError , NameIdGen , Inference , Output TypedInstanceHole , Termination , Output CastHole , Reader InsertedArgsStack ] r ) => Maybe Expression -> Expression -> Sem r TypedExpression
1246
+ -- | The _typeHint is used for trailing holes only
1247
+ holesHelper :: forall r . (Members '[Reader InfoTable , Reader BuiltinsTable , ResultBuilder , Reader LocalVars , Error TypeCheckerError , NameIdGen , Inference , Output TypedInstanceHole , Termination , Output CastHole , Reader InsertedArgsStack ] r ) => TypeHint -> Expression -> Sem r TypedExpression
1223
1248
holesHelper mhint expr = do
1224
1249
let (f, args) = unfoldExpressionApp expr
1225
1250
hint
1226
1251
| null args = mhint
1227
- | otherwise = Nothing
1252
+ | otherwise = set typeHint Nothing mhint
1228
1253
arityCheckBuiltins f args
1229
1254
fTy <- inferLeftAppExpression hint f
1230
1255
iniBuilderType <- mkInitBuilderType fTy
@@ -1363,7 +1388,7 @@ holesHelper mhint expr = do
1363
1388
gets (^. appBuilderType) >>= applyCtx >>= modify' . set appBuilderType
1364
1389
1365
1390
goArgs :: forall r' . (r' ~ State AppBuilder ': Output InsertedArg ': r ) => Sem r' ()
1366
- goArgs = peekArg >>= maybe (insertTrailingHolesMay mhint) goNextArg
1391
+ goArgs = peekArg >>= maybe (insertTrailingHolesMay ( mhint ^. typeHint) ) goNextArg
1367
1392
where
1368
1393
insertTrailingHolesMay :: Maybe Expression -> Sem r' ()
1369
1394
insertTrailingHolesMay = flip whenJust insertTrailingHoles
0 commit comments