partialApply_O :: QProg -> QProg
partialApply_O (viewl -> x :< (viewl -> z :< (viewl -> (QFunc "call") :< rest))) = case z of
  QQuote (viewr -> rest_pattern :> (QVar v)) b -> case x of
    QFunc _ -> no_opt
    _ -> (partialApplySub (QVar v, x) (QQuote rest_pattern b)) <| (QFunc "call") <| (partialApply_O rest)
  QQuote (viewr -> rest_pattern :> v) b -> if v == x
    then (QQuote rest_pattern b) <| (QFunc "call") <| (partialApply_O rest)
    else no_opt
  _ -> no_opt
  where no_opt = x <| z <| (QFunc "call") <| (partialApply_O rest)
partialApply_O :: QProg -> QProg
partialApply_O (viewl -> x :< (viewl -> z :< (viewl -> (QFunc "call") :< rest))) = case z of
  QQuote (viewr -> rest_pattern :> (QVar v)) b -> case x of
    QFunc _ -> no_opt
    _ -> (partialApplySub (QVar v, x) (QQuote rest_pattern b)) <| (QFunc "call") <| (partialApply_O rest)
  QQuote (viewr -> rest_pattern :> v) b -> if v == x
    then (QQuote rest_pattern b) <| (QFunc "call") <| (partialApply_O rest)
    else no_opt
  _ -> no_opt
  where no_opt = x <| z <| (QFunc "call") <| (partialApply_O rest)
partialApply_O (viewl -> x :< (viewl -> z :< (viewl -> (QFunc "call") :< rest))) = case z of
  QQuote (viewr -> rest_pattern :> (QVar v)) b -> case x of
    QFunc _ -> no_opt
    _ -> (partialApplySub (QVar v, x) (QQuote rest_pattern b)) <| (QFunc "call") <| (partialApply_O rest)
  QQuote (viewr -> rest_pattern :> v) b -> if v == x
    then (QQuote rest_pattern b) <| (QFunc "call") <| (partialApply_O rest)
    else no_opt
  _ -> no_opt
  where no_opt = x <| z <| (QFunc "call") <| (partialApply_O rest)