私は「RealWorldHaskell」(すばらしい本)を読んでいて、コンパイラがオーバーロードされた関数をどのように選択するかについて混乱しています。
型クラスがある場合
type JSONError = String
class JSON a where
toJValue :: a -> JValue
fromJValue :: JValue -> Either JSONError a
そしてこれらのような2つのインスタンス
instance JSON Bool where
toJValue = JBool
fromJValue (JBool b) = Right b
fromJValue _ = Left "not a JSON boolean"
と
instance JSON String where
toJValue = JString
fromJValue (JString s) = Right s
fromJValue _ = Left "not a JSON string"
コンパイラは、たとえば整数など、2つの「fromJValue」関数からどのように選択できますか?