on master help sign in
cosmetic: move constrainAnnotatedDef below other def code
c3ee8caEvan Czaplicki
src/Type/Constrain/Expression.hs+31−31
@@ -507,16 +507,44 @@ constrainDef env info (Canonical.Def _ (A.A patternRegion pattern) expr maybeTip
507 let qs = [] -- should come from the def, but I'm not sure what would live there...
507 let qs = [] -- should come from the def, but I'm not sure what would live there...
508 in
508 in
509 case (pattern, maybeTipe) of
509 case (pattern, maybeTipe) of
510− (P.Var name, Just (A.A typeRegion tipe)) ->
511− constrainAnnotatedDef env info qs patternRegion typeRegion name expr tipe
512−
513 (P.Var name, Nothing) ->
510 (P.Var name, Nothing) ->
514 constrainUnannotatedDef env info qs patternRegion name expr
511 constrainUnannotatedDef env info qs patternRegion name expr
515
512
513+ (P.Var name, Just (A.A typeRegion tipe)) ->
514+ constrainAnnotatedDef env info qs patternRegion typeRegion name expr tipe
515+
516 _ ->
516 _ ->
517 error "canonical definitions must not have complex patterns as names in the contstraint generation phase"
517 error "canonical definitions must not have complex patterns as names in the contstraint generation phase"
518
518
519
519
520+constrainUnannotatedDef
521+ :: Env.Environment
522+ -> Info
523+ -> [String]
524+ -> R.Region
525+ -> String
526+ -> Canonical.Expr
527+ -> IO Info
528+constrainUnannotatedDef env info qs patternRegion name expr =
529+ do -- Some mistake may be happening here. Currently, qs is always [].
530+ rigidVars <- mapM mkRigid qs
531+
532+ v <- mkVar Nothing
533+
534+ let tipe = VarN v
535+
536+ let env' = Env.addValues env (zip qs rigidVars)
537+
538+ con <- constrain env' expr tipe
539+
540+ return $ info
541+ { iRigid = rigidVars ++ iRigid info
542+ , iFlex = v : iFlex info
543+ , iHeaders = Map.insert name (A.A patternRegion tipe) (iHeaders info)
544+ , iC2 = con /\ iC2 info
545+ }
546+
547+
520constrainAnnotatedDef
548constrainAnnotatedDef
521 :: Env.Environment
549 :: Env.Environment
522 -> Info
550 -> Info
@@ -554,31 +582,3 @@ constrainAnnotatedDef env info qs patternRegion typeRegion name expr tipe =
554 { iSchemes = scheme : iSchemes info
582 { iSchemes = scheme : iSchemes info
555 , iC1 = iC1 info /\ ex [var] (defCon /\ fl rigidVars annCon)
583 , iC1 = iC1 info /\ ex [var] (defCon /\ fl rigidVars annCon)
556 }
584 }
557−
558−
559−constrainUnannotatedDef
560− :: Env.Environment
561− -> Info
562− -> [String]
563− -> R.Region
564− -> String
565− -> Canonical.Expr
566− -> IO Info
567−constrainUnannotatedDef env info qs patternRegion name expr =
568− do -- Some mistake may be happening here. Currently, qs is always [].
569− rigidVars <- mapM mkRigid qs
570−
571− v <- mkVar Nothing
572−
573− let tipe = VarN v
574−
575− let env' = Env.addValues env (zip qs rigidVars)
576−
577− con <- constrain env' expr tipe
578−
579− return $ info
580− { iRigid = rigidVars ++ iRigid info
581− , iFlex = v : iFlex info
582− , iHeaders = Map.insert name (A.A patternRegion tipe) (iHeaders info)
583− , iC2 = con /\ iC2 info
584− }