假设我有两个这样的功能:
food :: Eatable a => String -> a
food animalType = getAnimal animalType
getAnimal :: Eatable a => String -> a
getAnimal "cat" = Cat
getAnimal "dog" = Dog
WhereCat
和Dog
are 都是Eatable
s。
所以我可以这样调用食物函数:
let cat = food "cat" :: Cat
但是把字符串放在那里似乎是多余的。有没有办法将其更改为:
let cat = food :: Cat