haskellで文字列を数字に変換する
haskellで文字列を数字に変換するにはreadを使う。
ただしreadは多相型なので後ろに型の識別子が必要。
Prelude> :type read read :: (Read a) => String -> a Prelude> read "123" <interactive>:1:0: Ambiguous type variable `a' in the constraint: `Read a' arising from a use of `read' at <interactive>:1:0-9 Probable fix: add a type signature that fixes these type variable(s) Prelude> read "123"::Int 123 Prelude> read "123"::Float 123.0 Prelude> read "123"::Integer 123
エラーにちゃんとかいてあるじゃないか…
一度自分で多相型の関数作る必要があるな。