[Haskell-cafe] exporting Constructors as pattern-only
Andrew.Butterfield at scss.tcd.ie
Fri May 19 08:43:56 UTC 2017
is there any way in Haskell to export a *data* type so that importing modules can pattern match,
but not use the constructors to build anything?
My use case is an AST with invariant - I want the convenience of pattern matching
with the safety of having to build using functions exported by the model rather than the constructors directly.
data T = T1 Bool | T2 Int | TT T T
t1 :: Bool -> T
t2 :: Int -> T
tt :: T -> T -> T
from outside I can write
f(T1 False) = tt (t1 True) (t2 42)
f(T1 False) = TT (T1 True) (T2 42) ?
School of Computer Science & Statistics
Dublin 2, Ireland
More information about the Haskell-Cafe