How do I write higher-order functions that take polymorphic functions as arguments in Typed Racket?

落爺英雄遲暮 提交于 2019-12-04 03:11:34

You have to manually instantiate the polymorphism in this case:

->  (map (inst identity Integer) '(1 2 3))
- : (Listof Integer) [more precisely: (Pairof Integer (Listof Integer))]
'(1 2 3)

The reason is explained in the Typed Racket Guide here:

Typed Racket’s local type inference algorithm is currently not able to infer types for polymorphic functions that are used on higher-order arguments that are themselves polymorphic.

(see docs for more explanation and examples)

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