Reputation: 667
If I have a type, eg insurance number which is a int.
Is there anyway I can convert insurancenumber to int for use in a comparing function?
intNI :: NI -> Int
intNI x = Int (x)
Upvotes: 0
Views: 908
Reputation: 15028
If, as I suspect, NI
is defined as
type NI = Int
then you can just say
intNI :: NI -> Int
intNI x = fromIntegral x
or, after eta-conversion:
intNI :: NI -> Int
intNI = fromIntegral
On the other hand, it seems that
data NI = NI Int
in which case the right way to go is pattern matching, like so:
intNI (NI x) = x
This will extract the x
bit out of NI x
and return it.
Upvotes: 1