How to disambiguate selector function?

流过昼夜 提交于 2019-12-03 12:40:07

this should work:

main = putStrLn $ name (dog :: Dog)

see DuplicateRecordFields for details:

Bare uses of the field refer only to the selector function, and work only if this is unambiguous.

and

However, we do not infer the type of the argument to determine the datatype, or have any way of deferring the choice to the constraint solver.

The example there is very much like yours:

bad (p :: Person) = personId p

this will not work when there is another record with a personId field in scope - even if it seems to be obvious :(

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!