I am writing a simple ADT for the grid axis. In my application grid, it can be either regular (with a constant step between coordinates) or irregular (otherwise). Of course, a regular grid is just a special case of an irregular grid, but in some situations it may be advisable to distinguish them (for example, to perform some optimizations). So, I declare my ADT as follows:
data GridAxis = RegularAxis (Float, Float) Float -- (min, max) delta | IrregularAxis [Float] -- [xs]
But I do not want the user to create invalid axes with max < min or with an unordered list xs . So, I am adding smart build functions that perform some basic checks:
regularAxis :: (Float, Float) -> Float -> GridAxis regularAxis (a, b) dx = RegularAxis (min ab, max ab) (abs dx) irregularAxis :: [Float] -> GridAxis irregularAxis xs = IrregularAxis (sort xs)
I don’t want the user to create meshes directly, so I don’t add GridAxis data GridAxis to the module export list:
module GridAxis ( GridAxis, regularAxis, irregularAxis, ) where
But it turned out that after that I can no longer use pattern matching on GridAxis . Trying to use it
import qualified GridAxis as GA test :: GA.GridAxis -> Bool test axis = case axis of GA.RegularAxis -> True GA.IrregularAxis -> False
gives the following compiler error:
src/Physics/ImplicitEMC.hs:7:15: Not in scope: data constructor `GA.RegularAxis' src/Physics/ImplicitEMC.hs:8:15: Not in scope: data constructor `GA.IrregularAxis'
Is there anything for this?