开发者

Type definition for dimensions

开发者 https://www.devze.com 2023-02-17 03:23 出处:网络
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).

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 d开发者_JAVA技巧imension 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消