generateInvocation' :: CpdR.Definitions -> [G S] -> [G S] -> G S
generateInvocation' defs gs v =
    let Just (goal, n, as) = find ((v ==) . fst3) defs in
    let name = n in
    let args = generateArgs as in
    let res = call name args in
    call name args
  where
    generateArgs xs =
      case CpdR.unifyInvocationLists v gs (Just Subst.empty) of
        Just subst ->
          map (\a -> fromMaybe (V a) (Subst.lookup a subst)) xs
        Nothing -> error (printf "Failed to generate invocation for %s" (show v))
    getArgs (Invoke _ args) = args
generateInvocation' :: CpdR.Definitions -> [G S] -> [G S] -> G S
generateInvocation' defs gs v =
    let Just (goal, n, as) = find ((v ==) . fst3) defs in
    let name = n in
    let args = generateArgs as in
    let res = call name args in
    call name args
  where
    generateArgs xs =
      case CpdR.unifyInvocationLists v gs (Just Subst.empty) of
        Just subst ->
          map (\a -> fromMaybe (V a) (Subst.lookup a subst)) xs
        Nothing -> error (printf "Failed to generate invocation for %s" (show v))
    getArgs (Invoke _ args) = args
generateInvocation' defs gs v =
    let Just (goal, n, as) = find ((v ==) . fst3) defs in
    let name = n in
    let args = generateArgs as in
    let res = call name args in
    call name args
  where
    generateArgs xs =
      case CpdR.unifyInvocationLists v gs (Just Subst.empty) of
        Just subst ->
          map (\a -> fromMaybe (V a) (Subst.lookup a subst)) xs
        Nothing -> error (printf "Failed to generate invocation for %s" (show v))
    getArgs (Invoke _ args) = args