[haskell] Can I rewrite 2 functions to use same case expression
Viewer
- withVersionProxy :: a -> FormVersion -> RDParams a -> (forall b e. (EvalParams b ~ RDParams a, FormConstraints b) => Proxy b -> EvalParams b -> c) -> Maybe c
- withVersionProxy key ver p f =
- case ver of
- FormVersion 1 -> Just $ f (Proxy :: Proxy (Form_1)) p
- FormVersion 2 -> Just $ f (Proxy :: Proxy (Form_2)) p
- otherwise -> Nothing
- withVersion :: a -> FormVersion -> (forall e. (EvalParams e ~ RDParams a, FormConstraints e) => Registration e) -> (forall b e. (EvalParams b ~ RDParams a, FormConstraints b) => Registration b -> c) -> Maybe c
- withVersion key ver gen f =
- case ver of
- FormVersion 1 -> Just $ f (gen :: Registration Form_1)
- FormVersion 2 -> Just $ f (gen :: Registration Form_2)
- otherwise -> Nothing
Editor
You can edit this paste and save as new: