Type list->sbf.

This commit is contained in:
Sergiu Ivanov 2022-04-25 23:29:48 +02:00
parent 945dfe1490
commit ef979d6dce
2 changed files with 19 additions and 9 deletions

View File

@ -31,7 +31,7 @@
(struct-out tbf) tbf-w tbf-θ boolean->01/vector apply-tbf apply-tbf/boolean
list->tbf lists->tbfs read-org-tbfs tbf-tabulate* tbf-tabulate
tbf-tabulate*/boolean sbf? sbf)
tbf-tabulate*/boolean sbf? sbf list->sbf)
(module+ test
(require typed/rackunit))
@ -556,6 +556,13 @@
(test-case "sbf"
(check-equal? (sbf #(1 -1)) (tbf '#(1 -1) 0))))
(: list->sbf (-> (Listof Real) tbf))
(define (list->sbf lst) (sbf (list->vector lst)))
(module+ test
(test-case "list->sbf"
(check-equal? (list->sbf '(1 -1)) (tbf '#(1 -1) 0))))
(module untyped racket
(module+ test
(require rackunit))
@ -646,7 +653,7 @@
(struct-out tbf) tbf-w tbf-θ boolean->01/vector apply-tbf apply-tbf/boolean
list->tbf lists->tbfs read-org-tbfs tbf-tabulate* tbf-tabulate
tbf-tabulate*/boolean sbf? sbf)
tbf-tabulate*/boolean sbf? sbf list->sbf)
(require (rename-in (submod 'typed untyped)
[tabulate tabulate/untyped]
@ -655,7 +662,6 @@
(provide
;; Functions
(contract-out
[list->sbf (-> (listof number?) sbf?)]
[read-org-sbfs (->* (string?) (#:headers boolean?) (listof sbf?))]))
(module+ test
@ -666,13 +672,7 @@
;;; Threshold Boolean functions
;;; ===========================
;;; Converts a list of numbers to an SBF. The elements of the list
;;; are taken to be the weights of the SBF.
(define list->sbf (compose sbf list->vector))
(module+ test
(test-case "list->sbf"
(check-equal? (list->sbf '(1 -1)) (tbf '#(1 -1) 0))))
;;; Reads a list of SBF from an Org-mode string containing a sexp,
;;; containing a list of lists of numbers. If headers is #t, drops

View File

@ -582,6 +582,16 @@ Creates a TBF which is an SBF from a vector of weights.
(sbf #(1 -1))
]}
@defproc[(list->sbf [lst (Listof Real)])
tbf]{
Converts a list of numbers to an SBF. The elements of the list are taken to be
the weights of the SBF.
@ex[
(list->sbf '(1 -1))
]}
@section[#:tag "fuctions/untyped"]{Untyped definitions}
@defmodule[(submod dds/functions typed untyped)]