Skip to content

SCC analysis will fail for pattern bindings that bind a variable

As an example, it will fail for Nothing = Nothing, and the reason is the following snippet of code:

sccWithSigs :: [TVar] -> [ValBind] -> ([ValBind], [ValGroup])
sccWithSigs wSigs vbs
  = second (map valGroup . stronglyConnComp) (foldl' step ([], []) vbs)
  where
    step (vbs, components) vb
      | noSig vb  = (vbs, node vb : components)
      | otherwise = (vb : vbs, components)

    valGroup (AcyclicSCC vb)   = NonRec vb
    valGroup (NECyclicSCC vbs) = Rec vbs

    node d@(FunBind var mchs) = (d, var, concatMap fvMatch mchs)
    node d@(PatBind pat expr) = (d, head $ fv pat, fv expr)
                                    -- Here! In the example above, we'd get (head []), which causes a runtime error. Terrible!.       
    noSig (FunBind var _) = var `notElem` wSigs
    noSig (PatBind pat _) = any (`notElem` wSigs) (fv pat)
Edited by Artin Ghasivand