Type lists->tbfs.

This commit is contained in:
Sergiu Ivanov 2022-04-21 15:37:55 +02:00
parent d9734a5a35
commit 1f01917f8a
2 changed files with 22 additions and 12 deletions

View file

@ -28,7 +28,7 @@
random-boolean-table random-boolean-function random-boolean-function/list
(struct-out tbf) tbf-w tbf-θ boolean->01/vector apply-tbf apply-tbf/boolean
list->tbf)
list->tbf lists->tbfs)
(module+ test
(require typed/rackunit))
@ -404,6 +404,15 @@
(test-case "list->tbf"
(check-equal? (list->tbf '(1 2 3)) (tbf #(1 2) 3))))
(: lists->tbfs (-> (Listof (Listof Real)) (Listof tbf)))
(define (lists->tbfs lsts)
(map list->tbf lsts))
(module+ test
(test-case "read-tbfs"
(check-equal? (lists->tbfs '((1 2 3) (2 3 4)))
(list (tbf '#(1 2) 3) (tbf '#(2 3) 4)))))
(module untyped racket
(module+ test
(require rackunit))
@ -491,7 +500,7 @@
random-boolean-table random-boolean-function random-boolean-function/list
(struct-out tbf) tbf-w tbf-θ boolean->01/vector apply-tbf apply-tbf/boolean
list->tbf)
list->tbf lists->tbfs)
(require (rename-in (submod 'typed untyped)
[tabulate tabulate/untyped]
@ -500,7 +509,6 @@
(provide
;; Functions
(contract-out
[lists->tbfs (-> (listof (listof number?)) (listof tbf?))]
[read-org-tbfs (->* (string?) (#:headers boolean?) (listof tbf?))]
[tbf-tabulate* (-> (listof tbf?) (listof (listof (or/c 0 1))))]
[tbf-tabulate (-> tbf? (listof (listof (or/c 0 1))))]
@ -520,15 +528,6 @@
;;; Threshold Boolean functions
;;; ===========================
;;; Reads a list of TBF from an Org-mode table read by
;;; read-org-sexp.
(define lists->tbfs ((curry map) list->tbf))
(module+ test
(test-case "read-tbfs"
(check-equal? (lists->tbfs '((1 2 3) (2 3 4)))
(list (tbf '#(1 2) 3) (tbf '#(2 3) 4)))))
;;; Reads a list of TBF from an Org-mode string containing a sexp,
;;; containing a list of lists of numbers. If headers is #t, drops
;;; the first list, supposing that it contains the headers of the

View file

@ -424,6 +424,17 @@ be the threshold, while the other elements are taken to be the weights.
(list->tbf '(1 2 3))
]}
@defproc[(lists->tbfs [lsts (Listof (Listof Real))]) (Listof tbf)]{
Converts multiple lists of numbers to a list of TBFs.
The main use is for reading TBFs from Org-mode tables read by
@racket[read-org-sexp].
@examples[#:eval functions-evaluator
(lists->tbfs '((1 2 3) (2 3 4)))
]}
@section[#:tag "fuctions/untyped"]{Untyped definitions}
@defmodule[(submod dds/functions typed untyped)]