我有data RegEx
并且我想实施instance Show a => Show RegEx a
. 这是我的代码:
showAtom :: Show a => RegEx a -> String
showAtom (Lit x) = show x
showAtom r = "(" ++ (show r) ++ ")"
instance Show a => Show (RegEx a) where
show (Lit x) = show [x]
show (Opt r) = (showAtom r) ++ "?"
show (Alt p q) = (showAtom p) ++ "|" ++ (showAtom q)
show (Seq p q) = (show p) ++ (show q)
show (Rep r) = (showAtom r) ++ "*"
该showAtom
函数只是一个实现细节。我有什么办法可以隐藏它,使其仅在instance
定义中可见?或者更好的是,使其仅在show
.