如何定义尺寸的类型?
你可以用另一种类型来定义类型吗? (即一英寸是72个PostScript点)。 为维度单位创建新类型还有意义吗?
我已经看过其他类型单元的库,但我感兴趣的维度是:缩放点(最小,也许是Int?),点(65536缩放点),异食(12点)等。
How would one define a type for dimensions?
Can you define a type in terms of another type? (i.e. an inch is 72 PostScript points). Would it even make sense to make a new type for a dimension unit?
I've seen libraries for other kind of units, but the dimensions I'd be interested in are: scaled point (smallest, maybe Int?), point (65536 scaled points), pica (12 points), etc.
最满意答案
我认为这是幽灵类型可以帮助的地方。 尺寸包是开始了解它们的好地方。 代码是有识字的Haskell,非常易读,所以我建议阅读。
I think this is where phantom types can help. The dimensional package is a good place to start to understand them. The code is literate Haskell and very readable so I'd recommend reading through that.
更多推荐
发布评论