関数型プログラミング言語Haskell Part7
■ このスレッドは過去ログ倉庫に格納されています
0614デフォルトの名無しさん
2007/06/30(土) 14:40:25import Data.HashTable
import Data.Typeable
hoge a = if typeOf a == typeOf "A"
then do hash <- new (==) hashString
hoge2 hash a
else do hash <- new (==) hashInt
hoge2 hash a
hoge2 hash' b = update hash' b "HOGE"
これだと、次のようなエラーが出る。
test.hs:8:28:
Couldn't match expected type `Int' against inferred type `String'
Expected type: Int
Inferred type: String
In the second argument of `hoge2', namely `a'
In the expression: hoge2 hash a
関数の中では、型変数の型は一つしかとれないということなのかな・・・?
こういう場合はどうしたらいいんだろう。
■ このスレッドは過去ログ倉庫に格納されています