
7 Aug
2016
7 Aug
'16
8:49 a.m.
Imants Cekusins
for a Bool-like newtype:
newtype B = B Bool
, is there an easy way to use this newtype B in place of Bool?
e.g.
let b1 = B True in if b1 then 1 else 0
?
Imants, You can create a function that converts a B to a Bool: toBool :: B -> Bool toBool B b = b And then use the result of applying that function to your variable: let b1 = B True in if toBool b1 then 1 else 0 To do anything like this automatically would seem to me to defeat the purpose of having distinct types, which is to clearly articulate what values are appropriate in particular contexts. Mike.