How to create a type bounded within a certain range

前端 未结 2 1353
没有蜡笔的小新
没有蜡笔的小新 2020-12-06 09:30

I would like to create a new integral type which is bounded to a certain range. I have tried:

data PitchClass = PC Int deriving (Ord, Eq, Show)

instance Bou         


        
2条回答
  •  失恋的感觉
    2020-12-06 10:31

    Yes, not exporting the data constructor from the module is the way to go.

    Instead, you export a function which does the checking as you said. This is often called a smart constructor.

提交回复
热议问题