*B> map toBool onOffList <interactive>:13:12: error:• Couldn't match type ‘A.OnOff’ with ‘OnOff’ NB:‘OnOff’ is defined at B.hs:(6,1)-(9,21)‘A.OnOff’ is defined at A.hs:(3,1)-(6,21) Expected type: [OnOff] Actual type: [A.OnOff]• In the second argument of‘map’, namely ‘onOffList’ In the expression: map toBool onOffList In an equation for ‘it’: it = map toBool onOffList
ここで unsafeCoerce を使います。
B.hs
module B (toBool,onOffList2BoolList) whereimport A (onOffList)import Unsafe.Coerce (unsafeCoerce)dataOnOff= On| Offderiving (Eq,Show)onOffList2BoolList:: [OnOff] -> [Bool]onOffList2BoolList = map toBool . unsafeCoercetoBool::OnOff->BooltoBool On = TruetoBool Off = False
実行してみましょう。
ghci
*B> onOffList2BoolList onOffList<interactive>:23:20: error:• Couldn't match type ‘A.OnOff’ with ‘OnOff’ NB:‘OnOff’ is defined at B.hs:(6,1)-(9,21)‘A.OnOff’ is defined at A.hs:(3,1)-(6,21) Expected type: [OnOff] Actual type: [A.OnOff]• In the first argument of‘onOffList2BoolList’, namely ‘onOffList’ In the expression: onOffList2BoolList onOffList In an equation for ‘it’: it = onOffList2BoolList onOffList