functional-programmingracketstatic-typingplai

plai-typed : how to define function type?


I'm playing with plai-type language. I have a function which should consume a predicate function (returning true or false) and a list of items.

My code looks like:

(define-type-alias IndexT (listof IndexItemT))

(define (index->filter pf [index : IndexT]) : IndexT
  (filter pf index))

and I'd like to express that pf can consume value of type IndexItemT and return bool.

Is it possible to write it in plai-typed lang? If yes, how?


Solution

  • Yes. You can use -> type constructor to express the type of pf.

    (define (index->filter [pf : (IndexItemT -> boolean)] [index : IndexT]) : IndexT
      ....)