I've recently noticed some surprising behavior from `opt/c` with regards to
whether it produces a `flat-contract?` when its argument is flat: sometimes
it does, and sometimes it doesn't, even when given the same contract.

The following program is the best I've come up with at demonstrating the
inconsistency consistently. The only difference I can discern between
`two-step-opt-state/c` and `one-step-opt-state/c` is that the latter is
statically visible, but if anything that makes it more surprising that
`one-step-opt-state/c` doesn't produce a `flat-contract?`.

>From looking at the expansion, though, it looks `two-step-opt-state/c` is
just `(coerce-contract 'opt/c state/c)`, so I guess the more complicated
expansion of `one-step-opt-state/c` is where the flatness gets lost.

#lang racket

(struct state (prev now next)
  #:transparent)

(define state/c
  (or/c (struct/c state
                  (listof number?)
                  number?
                  (listof number?))
        (struct/c state
                  '()
                  'start
                  (non-empty-listof number?))
        (struct/c state
                  (non-empty-listof number?)
                  'end
                  '())))

;; returns #t, as it should
(flat-contract? state/c)

(define two-step-opt-state/c
  (opt/c state/c))

;; also returns #t, which makes sense
(flat-contract? two-step-opt-state/c)

(define one-step-opt-state/c
  (opt/c (or/c (struct/c state
                         (listof number?)
                         number?
                         (listof number?))
               (struct/c state
                         '()
                         'start
                         (non-empty-listof number?))
               (struct/c state
                         (non-empty-listof number?)
                         'end
                         '()))))

;; inexplicably returns #f
(flat-contract? one-step-opt-state/c)

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to