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

前端 未结 1 1609
無奈伤痛
無奈伤痛 2021-01-05 01:36

For example, how can I write a version of map that will work with polymorphic functions in Typed Racket? I use a simple id function defined as:

相关标签:
1条回答
  • 2021-01-05 02:10

    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)

    0 讨论(0)
提交回复
热议问题