on master help sign in
cosmetic: move constrainAnnotatedDef below other def code
commitc3ee8ca9be43ed1a41e38c7828ebef07df35ba03 authorEvan Czaplicki <evancz@users.noreply.github.com> dateSat 17 Sep 2016, 10:15 (10 years ago) parent7894dac
1 file changed+31−31
src/Type/Constrain/Expression.hs+31−31
src/Type/Constrain/Expression.hs+31−31
@@ -507,16 +507,44 @@ constrainDef env info (Canonical.Def _ (A.A patternRegion pattern) expr maybeTip
507507 let qs = [] -- should come from the def, but I'm not sure what would live there...
508508 in
509509 case (pattern, maybeTipe) of
510− (P.Var name, Just (A.A typeRegion tipe)) ->
511− constrainAnnotatedDef env info qs patternRegion typeRegion name expr tipe
512−
513510 (P.Var name, Nothing) ->
514511 constrainUnannotatedDef env info qs patternRegion name expr
515512
513+ (P.Var name, Just (A.A typeRegion tipe)) ->
514+ constrainAnnotatedDef env info qs patternRegion typeRegion name expr tipe
515+
516516 _ ->
517517 error "canonical definitions must not have complex patterns as names in the contstraint generation phase"
518518
519519
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+
520548constrainAnnotatedDef
521549 :: Env.Environment
522550 -> Info
@@ -554,31 +582,3 @@ constrainAnnotatedDef env info qs patternRegion typeRegion name expr tipe =
554582 { iSchemes = scheme : iSchemes info
555583 , iC1 = iC1 info /\ ex [var] (defCon /\ fl rigidVars annCon)
556584 }
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− }