Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如果我有一个类型,例如保险号码是一个整数。
无论如何我可以将 insurancenumber 转换为 int 以用于比较函数吗?
intNI :: NI -> Int intNI x = Int (x)
如果,正如我所怀疑的,NI被定义为
NI
type NI = Int
那么你可以说
intNI :: NI -> Int intNI x = fromIntegral x
或者,在 eta 转换之后:
intNI :: NI -> Int intNI = fromIntegral
另一方面,似乎
data NI = NI Int
在这种情况下,正确的方法是模式匹配,如下所示:
intNI (NI x) = x
这将从中提取该x位NI x并将其返回。
x
NI x