尺寸的类型定义(Type definition for dimensions)

系统教程 行业动态 更新时间:2024-06-14 16:55:57
尺寸的类型定义(Type definition for dimensions)

如何定义尺寸的类型?

你可以用另一种类型来定义类型吗? (即一英寸是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.

更多推荐

本文发布于:2023-04-10 11:16:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/d2436b1826f3d6214d7751c20f370b51.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:尺寸   定义   类型   dimensions   Type

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!