我有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
内才能看到它。
这只能将'showAtom'隐藏到其他模块。如果你还想将其从模块本身的其他部分隐藏起来,Mikhail Glushenkov的回答肯定是要走的路:) – gspr 2013-04-27 21:20:35